Is it possible to update the log level of a zap logger at runtime with MultiWriterSyncer?

45 views Asked by At

A follow-up to the question Is it possible to update the log level of a zap logger at runtime?

import (
    "sigs.k8s.io/controller-runtime/pkg/log/zap"
    "go.uber.org/zap/zapcore"
    lumberjack "gopkg.in/natefinch/lumberjack.v2"
)

func main() {
    ...
    opts := zap.Options{}
    lbjConfig := &lumberjack.Logger{}
    consoleDebugging := zapcore.Lock(os.Stderr)
    multiWriteSyncer := zapcore.NewMultiWriteSyncer(zapcore.AddSync(lbjConfig), consoleDebugging)
    opts.DestWriter = multiWriteSyncer

    ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
    ...
}
0

There are 0 answers