I am using zap library for logging and I try some simple scenario in which I want to log several entries without using Fields
. Unfortunately it doesn't work.
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
Is there a way to log any key/value pair without providing Field
arguments?
I tried removing the message
entry in the config without success (it omits all messages)
[I]s there a way to use zap without key and val ?
No.