-
Notifications
You must be signed in to change notification settings - Fork 23
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
Update logr and provide basic slog interop #31
base: main
Are you sure you want to change the base?
Conversation
* Add `formatterOrMarshal` and use for 3 duplicated calls * Add some newlines between blocks * Separate slog test setup, wrap `With` on same call instead of overwriting `log` variable
c5da60d
to
1eb1862
Compare
Thank you very much for this PR! Sadly I haven't used Do you know if this is the same for all logr implementations that supports It looks like this is expected and similar for However I'm still not sure I understand where the term |
The As to the differing output of nil errors: In the case of funcr the error gets converted to an interface here so the subsequent switch case for errors is not taken and it reaches this line where the value is hard-coded to In the case of logrusr the error is still an error when it gets added to the fields map and gets written using So logrusr just leverages the way that logrus would print errors whereas funcr elides the type and falls back to using a default for all nil values. |
Ok, I don't think I'll finish the slog handler implementation today. Are you okay with merging this as-is? I'm planning to replace a custom logrus+logr implementation with this repo, but I need 1.4.1. |
Thanks for explaining! But I'll have to keep asking more basic questions here. 🙈 With the current state of this PR I see how we can get a In fact, since Maybe I'm missing something but I can't see when › go test ./... -v -run ExampleNew -count 1
? github.com/bombsimon/logrusr/v4/example [no test files]
=== RUN ExampleNew
--- PASS: ExampleNew (0.00s)
PASS
ok github.com/bombsimon/logrusr/v4 0.001s |
You're right, I mixed things up. |
Awesome! I'll do that! Just let me know if there's anything else I can do! |
Update logr dependency to 1.4.1.
It is recommended that log sink implementations are compatible with slog.
This PR makes the
ToSlogHandler
direction work by adding support for slog values.There is one major caveat: errors passed to
slog.Error
must have the keyerror
otherwise the two (2) error fields will be displayed. One is theWithError
field that is always added and another is the actual error that will be printed.I moved the
WithError
call beforeWithFields
to ensure that the error at least can be overwritten.I think this problem can only be solved by implementing a slog handler that knows in what context it's OK to log nil errors and when they can be omitted.