diff --git a/pkg/util/logger/logger.go b/pkg/util/logger/logger.go index e67afb36b..4b60f02de 100644 --- a/pkg/util/logger/logger.go +++ b/pkg/util/logger/logger.go @@ -40,6 +40,9 @@ type Prm struct { // do not support runtime rereading dest string + + // PrependTimestamp specifies whether to prepend a timestamp in the log + PrependTimestamp bool } const ( @@ -116,11 +119,16 @@ func newConsoleLogger(prm *Prm) (*Logger, error) { c := zap.NewProductionConfig() c.Level = lvl c.Encoding = "console" - c.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder if prm.SamplingHook != nil { c.Sampling.Hook = prm.SamplingHook } + if prm.PrependTimestamp { + c.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder + } else { + c.EncoderConfig.TimeKey = "" + } + lZap, err := c.Build( zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel)), ) @@ -140,11 +148,16 @@ func newJournaldLogger(prm *Prm) (*Logger, error) { c := zap.NewProductionConfig() c.Level = lvl c.Encoding = "console" - c.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder if prm.SamplingHook != nil { c.Sampling.Hook = prm.SamplingHook } + if prm.PrependTimestamp { + c.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder + } else { + c.EncoderConfig.TimeKey = "" + } + encoder := zapjournald.NewPartialEncoder(zapcore.NewConsoleEncoder(c.EncoderConfig), zapjournald.SyslogFields) core := zapjournald.NewCore(lvl, encoder, &journald.Journal{}, zapjournald.SyslogFields)