-
Notifications
You must be signed in to change notification settings - Fork 1
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
Work-around for zerolog v1.32.0 #4
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 148 159 +11
=========================================
+ Hits 148 159 +11 ☔ View full report in Codecov by Sentry. |
Hi @madkins23 awesome, thanks a lot for the detailed analysis and the PR. I need to find some time to look at this in depth. I will soon |
The way I did it was a bit hacky already. Maybe it would be worth to check with zerolog's maintainers for some insights. |
I thought about that, but they have Reading over the zerolog issue about adding slog support (with several of your comments) I found the amusing note about basic |
There is now a PR on |
@madkins23 the PR you mention above has been merged, does that allow you to simplify this PR? |
The PR was merged but there is no My testing used:
so an update to I've been hoping for an update to A better PR for this issue is #6. This PR was an initial attempt and could be closed now. |
Closing as redundant. See #6. |
The change in
zerolog v1.32.0
that breaks things appears to be:which is called a couple of stack frames below:
which is present in at least two places in
zeroslog
code. Up until this change, passing in blankzerolog.Context
objects worked fine. Now it is necessary to pass in a proper logger inside of thezerolog.Context
object so that the non-nil
check for the logger'sio.Writer
shown above will not fail.Sadly the
l
(i.e. logger) field withinzerolog.Context
is private and there is no public function provided within thezerolog
code base to set it. The only way I could find to return a new context object is to usezerolog.Logger.With()
. However, that function manipulates a further private field in thezerolog.Logger
object namedcontext
,1 an array ofbyte
. This field is used to pre-format attributes for output viazerolog.Logger.WithAttrs()
orzerolog.Logger.WithGroup()
to speed up output. Using a previously modifiedzerolog.Logger
object to generate the requiredzerolog.Context
object cascades any previously changes made to the logger object down to the "new" logger within the returned context object.The only way I could work around all of the above was to capture the root logger object in both
zeroslog.Handler
andzeroslog.groupHandler
. Theroot
field in both places is used withWith()
to create the new context with the root logger. Any changes made to that logger (added to that logger's internalcontext
field) will thus be done to a "clean" logger and will not percolate to more embedded "with" objects. TheWith()
method is used against aLogger
object, not a pointer, so the root is not itself changed AFAIK.Short of changes to the
zerolog
code this is the best I could think of. I'm not 100% sure I got it right but it's passing tests now so I'm pushing the PR for evaluation and critique.Footnotes
Note that this is unfortunate naming as it is unrelated to either
zerolog.Context
orcontext.Context
. This is made clear (or further obfuscated, if you will) in the code forzerolog.Logger.With()
as well as the declaration ofzerolog.Logger
wherein bothcontext
andctx
are used as field names, the latter referring tocontext.Context
. ↩