mirror of https://github.com/sunface/rust-course
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
719 B
41 lines
719 B
package misc
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"go.uber.org/zap"
|
|
"go.uber.org/zap/zapcore"
|
|
)
|
|
|
|
// InitLog the logger interface
|
|
func InitLog(level string) {
|
|
var lv zapcore.Level
|
|
switch strings.ToLower(level) {
|
|
case "debug":
|
|
lv = zap.DebugLevel
|
|
case "info":
|
|
lv = zap.InfoLevel
|
|
case "warn":
|
|
lv = zap.WarnLevel
|
|
case "error":
|
|
lv = zap.ErrorLevel
|
|
}
|
|
|
|
atom := zap.NewAtomicLevel()
|
|
|
|
// To keep the example deterministic, disable timestamps in the output.
|
|
encoderCfg := zap.NewProductionEncoderConfig()
|
|
encoderCfg.EncodeTime = zapcore.ISO8601TimeEncoder
|
|
l := zap.New(zapcore.NewCore(
|
|
zapcore.NewConsoleEncoder(encoderCfg),
|
|
|
|
zapcore.Lock(os.Stdout),
|
|
atom,
|
|
), zap.AddCaller())
|
|
|
|
atom.SetLevel(lv)
|
|
|
|
Log = l
|
|
}
|