From 4caec4db1656d19ebb9f5b74a9d02f89beb90d6c Mon Sep 17 00:00:00 2001 From: Mehdi Ahmadi Date: Thu, 3 Sep 2020 00:13:23 +0200 Subject: [PATCH] Writer to log date / time in conistent format like in other places. --- logging/logging.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/logging/logging.go b/logging/logging.go index 72f76b5e6..5ef2a119a 100644 --- a/logging/logging.go +++ b/logging/logging.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "log" "strings" + "time" "github.com/hashicorp/go-syslog" "github.com/hashicorp/logutils" @@ -14,6 +15,14 @@ import ( // Levels are the log levels we respond to=o. var Levels = []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERR"} +type logWriter struct { +} + +// writer to output date / time in a standard format +func (writer logWriter) Write(bytes []byte) (int, error) { + return fmt.Print(time.Now().Format("2006-01-02T15:04:05.000Z0700") + " " + string(bytes)) +} + // Config is the configuration for this log setup. type Config struct { // Level is the log level to use. @@ -33,6 +42,9 @@ type Config struct { func Setup(config *Config) error { var logOutput io.Writer + log.SetFlags(0) + log.SetOutput(new(logWriter)) + // Setup the default logging logFilter := NewLogFilter() logFilter.MinLevel = logutils.LogLevel(strings.ToUpper(config.Level)) @@ -60,8 +72,8 @@ func Setup(config *Config) error { logOutput = io.MultiWriter(logFilter) } - log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds | log.LUTC) log.SetOutput(logOutput) + log.SetOutput(new(logWriter)) return nil }