Add disable_timestamp option (#288)

This commit is contained in:
CzBiX 2020-09-09 19:42:11 +08:00 committed by GitHub
parent 2e5a477a50
commit ef498a31da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -480,6 +480,7 @@ func configLogger(c *Config) error {
} }
l.SetLevel(logLevel) l.SetLevel(logLevel)
disableTimestamp := c.GetBool("logging.disable_timestamp", false)
timestampFormat := c.GetString("logging.timestamp_format", "") timestampFormat := c.GetString("logging.timestamp_format", "")
fullTimestamp := (timestampFormat != "") fullTimestamp := (timestampFormat != "")
if timestampFormat == "" { if timestampFormat == "" {
@ -492,10 +493,12 @@ func configLogger(c *Config) error {
l.Formatter = &logrus.TextFormatter{ l.Formatter = &logrus.TextFormatter{
TimestampFormat: timestampFormat, TimestampFormat: timestampFormat,
FullTimestamp: fullTimestamp, FullTimestamp: fullTimestamp,
DisableTimestamp: disableTimestamp,
} }
case "json": case "json":
l.Formatter = &logrus.JSONFormatter{ l.Formatter = &logrus.JSONFormatter{
TimestampFormat: timestampFormat, TimestampFormat: timestampFormat,
DisableTimestamp: disableTimestamp,
} }
default: default:
return fmt.Errorf("unknown log format `%s`. possible formats: %s", logFormat, []string{"text", "json"}) return fmt.Errorf("unknown log format `%s`. possible formats: %s", logFormat, []string{"text", "json"})

View File

@ -156,6 +156,8 @@ logging:
level: info level: info
# json or text formats currently available. Default is text # json or text formats currently available. Default is text
format: 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: # timestamp format is specified in Go time format, see:
# https://golang.org/pkg/time/#pkg-constants # https://golang.org/pkg/time/#pkg-constants
# default when `format: json`: "2006-01-02T15:04:05Z07:00" (RFC3339) # default when `format: json`: "2006-01-02T15:04:05Z07:00" (RFC3339)