-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: log/slog: allow implementing slog.Handler and logr.LogSink in the same type #59110
Comments
When using a second type, conversion between LogSink and Handler has to be done through additional interfaces. That may be the right solution anyway, because it gives implementors who want to support both more flexibility.
|
One could create an adapter type to wrap a |
I don't see us changing the name of |
Yes, let's close. I've been using the adapter type approach and it's not too bad. |
https://pkg.go.dev/golang.org/x/exp/slog#Handler and https://pkg.go.dev/github.com/go-logr/logr#LogSink are conceptually similar. If it was possible to implement both interfaces in the same type, then it would be simple to put either slog or logr as user-facing API on top of it.
This is currently not possible because of conflicting parameters for
Enabled
:Would it be possible to rename
Handler.Enabled
? Possible alternatives (just thinking out aloud):EnabledWithContext
SlogEnabled
LevelEnabled
Would it be useful? I think so - but probably not crucial.
My current workaround for https://github.com/go-logr/zapr/blob/master/zapr.go is a second type:
cc @jba @rsc
The text was updated successfully, but these errors were encountered: