I am trying to set up logging using this package github.com/uber-go/zap
.
I need to write:
- Info logs to stdout
- Error and Fatal logs to stderr
I tried to do this by setting up and building zap.Config
like this:
cfg = &zap.Config{
Encoding: "json",
Level: zap.NewAtomicLevelAt(zapcore.DebugLevel),
OutputPaths: []string{"stdout"},
ErrorOutputPaths: []string{"stderr"},
EncoderConfig: zapcore.EncoderConfig{
MessageKey: "message",
LevelKey: "level",
EncodeLevel: zapcore.CapitalLevelEncoder,
TimeKey: "time",
EncodeTime: zapcore.ISO8601TimeEncoder,
CallerKey: "caller",
EncodeCaller: zapcore.ShortCallerEncoder,
EncodeDuration: zapcore.MillisDurationEncoder,
},
}
Also I tried this way:
cfg = zap.NewProductionConfig()
cfg.OutputPaths = []string{"stdout"}
logger, err = cfg.Build(zap.AddCaller(), zap.AddCallerSkip(1))
But all logs are written to either stdout or stderr. How can I separate it?