[#1366] logger: Make timestamp prepending optional
Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
parent
96308a26c6
commit
ea48e928c8
1 changed files with 15 additions and 2 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue