Prechádzať zdrojové kódy

Add disable_timestamp option (#288)

CzBiX 4 rokov pred
rodič
commit
ef498a31da
2 zmenil súbory, kde vykonal 8 pridanie a 3 odobranie
  1. 6 3
      config.go
  2. 2 0
      examples/config.yml

+ 6 - 3
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"})

+ 2 - 0
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)