diff options
author | Derrick Anderson <derrick@andersonwebstudio.com> | 2018-05-15 11:19:27 -0400 |
---|---|---|
committer | Derrick Anderson <derrick@andersonwebstudio.com> | 2018-05-15 11:19:27 -0400 |
commit | 228bc4bd1dc84bf741978711b680a06dd9d67613 (patch) | |
tree | 5dae4ebc13fca2749b4278bba772ec13c0924e03 /mlog/default.go | |
parent | a1656dffa98fbc8865e476b214e4e0c562547d39 (diff) | |
parent | 9301e575c880970dc5642605adcc37903d176227 (diff) | |
download | chat-228bc4bd1dc84bf741978711b680a06dd9d67613.tar.gz chat-228bc4bd1dc84bf741978711b680a06dd9d67613.tar.bz2 chat-228bc4bd1dc84bf741978711b680a06dd9d67613.zip |
Merge remote-tracking branch 'origin/release-4.10' into merge410rc5
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...) +} |