From 7b9bfb783f9986dd039be0e7a8fbed649535e4e6 Mon Sep 17 00:00:00 2001 From: Aleksey Savchuk Date: Fri, 13 Sep 2024 15:49:10 +0300 Subject: [PATCH] [#1366] logger: Make timestamp prepending optional Signed-off-by: Aleksey Savchuk --- pkg/util/logger/logger.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/util/logger/logger.go b/pkg/util/logger/logger.go index e67afb36b..3c40f8495 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 ( @@ -120,6 +123,9 @@ func newConsoleLogger(prm *Prm) (*Logger, error) { if prm.SamplingHook != nil { c.Sampling.Hook = prm.SamplingHook } + if !prm.PrependTimestamp { + c.EncoderConfig.TimeKey = "" + } lZap, err := c.Build( zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel)), @@ -144,6 +150,9 @@ func newJournaldLogger(prm *Prm) (*Logger, error) { if prm.SamplingHook != nil { c.Sampling.Hook = prm.SamplingHook } + if !prm.PrependTimestamp { + c.EncoderConfig.TimeKey = "" + } encoder := zapjournald.NewPartialEncoder(zapcore.NewConsoleEncoder(c.EncoderConfig), zapjournald.SyslogFields)