From ef498a31dafe32facda24b1fe589ba2a5c11bdf2 Mon Sep 17 00:00:00 2001 From: CzBiX Date: Wed, 9 Sep 2020 19:42:11 +0800 Subject: [PATCH] Add disable_timestamp option (#288) --- config.go | 9 ++++++--- examples/config.yml | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/config.go b/config.go index 7b9df19..87f42e8 100644 --- a/config.go +++ b/config.go @@ -480,6 +480,7 @@ func configLogger(c *Config) error { } l.SetLevel(logLevel) + disableTimestamp := c.GetBool("logging.disable_timestamp", false) timestampFormat := c.GetString("logging.timestamp_format", "") fullTimestamp := (timestampFormat != "") if timestampFormat == "" { @@ -490,12 +491,14 @@ func configLogger(c *Config) error { switch logFormat { case "text": l.Formatter = &logrus.TextFormatter{ - TimestampFormat: timestampFormat, - FullTimestamp: fullTimestamp, + TimestampFormat: timestampFormat, + FullTimestamp: fullTimestamp, + DisableTimestamp: disableTimestamp, } case "json": l.Formatter = &logrus.JSONFormatter{ - TimestampFormat: timestampFormat, + TimestampFormat: timestampFormat, + DisableTimestamp: disableTimestamp, } default: return fmt.Errorf("unknown log format `%s`. possible formats: %s", logFormat, []string{"text", "json"}) diff --git a/examples/config.yml b/examples/config.yml index 0857885..7e86209 100644 --- a/examples/config.yml +++ b/examples/config.yml @@ -156,6 +156,8 @@ logging: level: info # json or text formats currently available. Default is text format: text + # Disable timestamp logging. useful when output is redirected to logging system that already adds timestamps. Default is false + #disable_timestamp: true # timestamp format is specified in Go time format, see: # https://golang.org/pkg/time/#pkg-constants # default when `format: json`: "2006-01-02T15:04:05Z07:00" (RFC3339)