-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Updating level a logger without creating a new pointer #793
Comments
You can update the level of a logger by:
|
@prashantv |
@prashantv |
We don't have official support for a write syncer that can be changed, but since it's an interface you can build your own implementation that does allow changing the underlying type AtomicWriteSyncer struct{
underlying atomic.Value // WriteSyncer
}
func NewAtomicWriteSyncer(ws zapcore.WriteSyncer) zapcore.WriteSyncer {
return &AtomicWriteSyncer{ws}
}
func (w *AtomicWriteSyncer) writeSyncer() zapcore.WriteSyncer {
return underlying.Load().(zapcore.WriteSyncer)
}
func (w *AtomicWriteSyncer) SetWriteSyncer(new zapcore.WriteSyncer) {
w.underlying.Store(new)
}
func (w *AtomicWriteSyncer) Write(p []byte) (int, error) {
return w.writeSyncer().Write(p)
}
func (w *AtomicWriteSyncer) Sync() error {
return w.writeSyncer().Sync()
} You would hold the reference to the above |
@prashantv |
Currently, I was trying to update the level of a logger by creating a new one an assign it to the old one but I noticed these two are pointing to different addresses and won't be useful during runtime. Like this:
I am wondering is it possible to change the level of a logger without recreating a new logger? Please consider that I wrote a custom logger.
The text was updated successfully, but these errors were encountered: