diff options
author | Jesse Hallam <jesse.hallam@gmail.com> | 2018-05-11 12:56:54 -0400 |
---|---|---|
committer | Derrick Anderson <derrick@andersonwebstudio.com> | 2018-05-11 12:56:54 -0400 |
commit | b4db76cedbd99bfcfb1c12444c5bd84e92ac01dc (patch) | |
tree | c63684db0fd9864b1a13d75f6138c24b6690b02c /mlog/default.go | |
parent | 91c998156336e34ab4b8979db77cc65c97a65782 (diff) | |
download | chat-b4db76cedbd99bfcfb1c12444c5bd84e92ac01dc.tar.gz chat-b4db76cedbd99bfcfb1c12444c5bd84e92ac01dc.tar.bz2 chat-b4db76cedbd99bfcfb1c12444c5bd84e92ac01dc.zip |
fix mlog-ing before initialized (#8753)
Dump mlog to STDOUT before initialized, to allow for logging failures
that occur due to config parsing, etc.
Fix file logging to honour logger.FileJson instead of copying the
logger.ConsoleJson setting.
Diffstat (limited to 'mlog/default.go')
-rw-r--r-- | mlog/default.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/mlog/default.go b/mlog/default.go new file mode 100644 index 000000000..366d22f88 --- /dev/null +++ b/mlog/default.go @@ -0,0 +1,50 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package mlog + +import ( + "encoding/json" + "fmt" +) + +// defaultLog manually encodes the log to STDOUT, providing a basic, default logging implementation +// before mlog is fully configured. +func defaultLog(level, msg string, fields ...Field) { + log := struct { + Level string `json:"level"` + Message string `json:"msg"` + Fields []Field `json:"fields,omitempty"` + }{ + level, + msg, + fields, + } + + if b, err := json.Marshal(log); err != nil { + fmt.Printf(`{"level":"error","msg":"failed to encode log message"}%s`, "\n") + } else { + fmt.Printf("%s\n", b) + } +} + +func defaultDebugLog(msg string, fields ...Field) { + defaultLog("debug", msg, fields...) +} + +func defaultInfoLog(msg string, fields ...Field) { + defaultLog("info", msg, fields...) +} + +func defaultWarnLog(msg string, fields ...Field) { + defaultLog("warn", msg, fields...) +} + +func defaultErrorLog(msg string, fields ...Field) { + defaultLog("error", msg, fields...) +} + +func defaultCriticalLog(msg string, fields ...Field) { + // We map critical to error in zap, so be consistent. + defaultLog("error", msg, fields...) +} |