2018-11-18 18:55:05 +01:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
2020-08-10 00:29:54 +02:00
|
|
|
// See LICENSE.txt for license information.
|
2018-11-18 18:55:05 +01:00
|
|
|
|
|
|
|
package mlog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2020-08-10 00:29:54 +02:00
|
|
|
"os"
|
2018-11-18 18:55:05 +01:00
|
|
|
)
|
|
|
|
|
2020-08-10 00:29:54 +02:00
|
|
|
// defaultLog manually encodes the log to STDERR, providing a basic, default logging implementation
|
2018-11-18 18:55:05 +01:00
|
|
|
// 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 {
|
2020-08-10 00:29:54 +02:00
|
|
|
fmt.Fprintf(os.Stderr, `{"level":"error","msg":"failed to encode log message"}%s`, "\n")
|
2018-11-18 18:55:05 +01:00
|
|
|
} else {
|
2020-08-10 00:29:54 +02:00
|
|
|
fmt.Fprintf(os.Stderr, "%s\n", b)
|
2018-11-18 18:55:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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...)
|
|
|
|
}
|