From de8e798052397c3faf477f4fc8c40993b90e4368 Mon Sep 17 00:00:00 2001 From: Claudio Costa Date: Fri, 27 Sep 2019 17:40:16 +0200 Subject: [PATCH] [MM-18638] Send mlog console output to stderr (#12366) * Send server logs to stderr * Update comment --- mlog/default.go | 7 ++++--- mlog/log.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/mlog/default.go b/mlog/default.go index 366d22f88a..b30ca16a20 100644 --- a/mlog/default.go +++ b/mlog/default.go @@ -6,9 +6,10 @@ package mlog import ( "encoding/json" "fmt" + "os" ) -// defaultLog manually encodes the log to STDOUT, providing a basic, default logging implementation +// defaultLog manually encodes the log to STDERR, providing a basic, default logging implementation // before mlog is fully configured. func defaultLog(level, msg string, fields ...Field) { log := struct { @@ -22,9 +23,9 @@ func defaultLog(level, msg string, fields ...Field) { } if b, err := json.Marshal(log); err != nil { - fmt.Printf(`{"level":"error","msg":"failed to encode log message"}%s`, "\n") + fmt.Fprintf(os.Stderr, `{"level":"error","msg":"failed to encode log message"}%s`, "\n") } else { - fmt.Printf("%s\n", b) + fmt.Fprintf(os.Stderr, "%s\n", b) } } diff --git a/mlog/log.go b/mlog/log.go index 07d35a32da..59bc91df2d 100644 --- a/mlog/log.go +++ b/mlog/log.go @@ -86,7 +86,7 @@ func NewLogger(config *LoggerConfiguration) *Logger { } if config.EnableConsole { - writer := zapcore.Lock(os.Stdout) + writer := zapcore.Lock(os.Stderr) core := zapcore.NewCore(makeEncoder(config.ConsoleJson), writer, logger.consoleLevel) cores = append(cores, core) }