-2

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.

Code

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)

blackgreen
  • 34,072
  • 23
  • 111
  • 129
Jenny M
  • 923
  • 1
  • 14
  • 37

1 Answers1

2

[I]s there a way to use zap without key and val ?

No.

Volker
  • 40,468
  • 7
  • 81
  • 87