zap icon indicating copy to clipboard operation
zap copied to clipboard

Change existing/cloned logger's LevelEnabler

Open JeanMertz opened this issue 6 years ago • 2 comments

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.

JeanMertz avatar May 21 '18 11:05 JeanMertz

Seconded, I've just hit this limitation as well.

ntnn avatar Jun 07 '18 09:06 ntnn

Related to #581.

AlekSi avatar Jun 25 '18 18:06 AlekSi