[#1366] logger: Make timestamp prepending optional

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
Aleksey Savchuk 2024-09-13 15:49:10 +03:00
parent 66e17f4b8e
commit 7b9bfb783f
No known key found for this signature in database

View file

@ -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)