Closed madkins23 closed 3 months ago
Would https://github.com/rs/zerolog/pull/575 let you solve your issue?
It fixes part of the problem. The other part would then just require a NewContext(logger)
function to be made public to create a new zerolog.Context
and set its private logger field.
Couldn't you use UpdateContext
for this?
TL;DR You're right, #575 would solve the more difficult part of my problem and existing methods on zerolog.Logger
appear to cover the rest.
My original work-around PR addressing v1.32.0
on phsym/zeroslog
used the With
method instead. UpdateContext
is a pointer method, With
isn't. I was thinking that the With
method was more likely to return a copy of the original logger as opposed to accidentally modifying it. I admit I didn't do any testing to see if that would happen.
I guess I considered my use of With
as off-label and possibly dangerous in the long run. Having a NewContext(logger)
in place seemed more correct and I didn't see #575. But if you're blessing UpdateContext
(or better yet With
IMHO) for that usage I'm good with it.
Yes I think With
should do the job.
Thanks. Looking forward to #575.
This is no longer necessary AFAIK. It would be nice to get a v1.33.0
tag to wrap it all up.
Done
Thanks! I've pushed a PR to phsym/zeroslog
based on #575. I'm going to close this PR.
@madkins23 have you considered submitting a PR to integrate your slog support in zerolog itself?
Not really. I'm not actually part of the phsym/zeroslog
development team so it's not really "my" slog support. I stepped in because I've been using rs/zerolog
for half a decade and like it very much. I was testing phsym/zeroslog
when V1.32.0
was tagged and the zeroslog
wrapper broke.
I did comment on doing something like this in #571 but I phrased it as rs/zerolog
V2 which (somewhat predictably in retrospect) didn't go down well. :-(
Let me think about it a bit. I might take a whack at it after I get through with the current set of tweaks to my test harness.
TL;DR Add function to create a zerolog.Context object with a logger copy and clear the copy's context byte array in order to fix breakage in
phsym/zeroslog
.The recent release of
rs/zerolog v1.32.0
brokephsym/zeroslog
. The latter was creating blankzerolog.Context
objects in several places and they worked fine up throughrs/zerolog v1.31.0
. I documented the issue in aphsym/zeroslog
PR, wherein I provided a potential solution to the issue that didn't require any changes tors/zerolog
.This PR provides a (hopefully) minor change to
rs/zerolog
that makes fixingphsym/zeroslog
simpler. I have already filed a second presumptivephsym/zeroslog
PR dependent on the changes in thisrs/zerolog
PR.Hopefully this PR will be an acceptable and minor change.
I gave the new function a long name because it is combining two issues. It could be broken down into:
NewContext(logger Logger)
which would just create the new
zerolog.Context
object with a logger and(l Logger) ClearContext()
which would clear the
context
byte array on the copiedLogger
.These two calls could be used instead of the single
NewContextWithResetLogger
call, something like this:If the latter is preferable I can generate a different PR.