zap
zap copied to clipboard
Change existing/cloned logger's LevelEnabler
I'd like to take an existing logger, use WithOptions
to clone/extend it, and also switch the LevelEnabler
to zap.AtomicLevel
(and keep a reference, to support log level switching on the newly created logger). That last part seems to be impossible right now.
I know I can set the LevelEnabler
using zap.Config{}
, but I'm dealing with an existing logger, and don't have access to the underlying config struct.
I also tried using zap.WrapCore()
as an option, but that gives me back the Core
interface, which hides access to the LevelEnabler
field.
I did notice NewCore(enc Encoder, ws WriteSyncer, enab LevelEnabler)
, but then I'd still need access to the original logger's Encoder
and WriteSyncer
, which I don't have, as far as I can tell.
The documentation of the config struct states:
// Config offers a declarative way to construct a logger. It doesn't do
// anything that can't be done with New, Options, and the various
// zapcore.WriteSyncer and zapcore.Core wrappers, but it's a simpler way to
// toggle common options.
But so far, I've not been able to find any way to set the LevelEnabler other than via the config struct.
Any help would be much appreciated.
Seconded, I've just hit this limitation as well.
Related to #581.