zerolog icon indicating copy to clipboard operation
zerolog copied to clipboard

Fix phsym/zeroslog breakage due to rs/zerolog v1.32.0

Open madkins23 opened this issue 11 months ago • 7 comments

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 broke phsym/zeroslog. The latter was creating blank zerolog.Context objects in several places and they worked fine up through rs/zerolog v1.31.0. I documented the issue in a phsym/zeroslog PR, wherein I provided a potential solution to the issue that didn't require any changes to rs/zerolog.

This PR provides a (hopefully) minor change to rs/zerolog that makes fixing phsym/zeroslog simpler. I have already filed a second presumptive phsym/zeroslog PR dependent on the changes in this rs/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 copied Logger.

These two calls could be used instead of the single NewContextWithResetLogger call, something like this:

newCtx := NewContext(logger)
newCtx.Logger().ClearContext()

If the latter is preferable I can generate a different PR.

madkins23 avatar Feb 29 '24 17:02 madkins23