Skip to content

How to add zapcore.NewMultiWriteSyncer in zap.Config #1391

Closed Answered by moluzhui
moluzhui asked this question in Q&A
Discussion options

You must be logged in to vote

I searched and found that it can be achieved using zap.WrapCore.

// hack replace zap config build core with lumberjack logger
func (o *Options) replaceLogCore(conf zap.Config) zap.Option {
    var enc zapcore.Encoder
    // Copy paste from zap.Config.buildEncoder.
    switch conf.Encoding {
    case jsonFormat:
        enc = zapcore.NewJSONEncoder(conf.EncoderConfig)
    case consoleFormat:
        enc = zapcore.NewConsoleEncoder(conf.EncoderConfig)
    default:
        panic("unknown encoding")
    }

    logSyncer := zapcore.AddSync(&lumberjack.Logger{
        Filename:   o.RotateLogPath,
        MaxSize:    o.RotateMaxSize, //MB
        MaxBackups: o.RotateMaxBackups,
        MaxAge:     

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by moluzhui
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant