关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。
想改进这个问题?将问题更新为 on-topic对于堆栈溢出。
2年前关闭。
Improve this question
我正在使用 zap 库进行日志记录,我尝试了一些简单的场景,我想在不使用 Fields
的情况下记录多个条目.不幸的是,它不起作用。
代码
cfg := zap.Config{
Encoding: "json",
Level: zap.NewAtomicLevelAt(zapcore.DebugLevel),
OutputPaths: []string{"stderr"},
ErrorOutputPaths: []string{"stderr"},
EncoderConfig: zapcore.EncoderConfig{
MessageKey: "message",
LevelKey: "level",
EncodeLevel: zapcore.CapitalLevelEncoder,
TimeKey: "time",
EncodeTime: zapcore.ISO8601TimeEncoder,
CallerKey: "caller",
EncodeCaller: zapcore.ShortCallerEncoder,
},
}
logger,_ := cfg.Build()
logger.Debug("This is a DEBUG message”) // works
logger.Info("This is an INFO message”, ”aaa”) // Error
有没有办法在不提供 Field
的情况下记录任何键/值对?论据? 我尝试删除
message
进入配置没有成功(它省略了所有消息)
最佳答案
[I]s there a way to use zap without key and val ?
不。
关于go - 如何在不使用字段的情况下在 Uber Zap 中记录键/值对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58507153/