forked from hbdmapi/huobi_futures_Golang
/
app_logger.go
56 lines (43 loc) · 1.22 KB
/
app_logger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package log
import (
"os"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var sugaredLogger *zap.SugaredLogger
var atomicLevel zap.AtomicLevel
func init() {
encoderCfg := zapcore.EncoderConfig{
TimeKey: "time",
MessageKey: "msg",
LevelKey: "level",
EncodeLevel: zapcore.CapitalColorLevelEncoder,
EncodeTime: zapcore.ISO8601TimeEncoder,
}
// define default level as debug level
atomicLevel = zap.NewAtomicLevel()
atomicLevel.SetLevel(zapcore.DebugLevel)
core := zapcore.NewCore(zapcore.NewConsoleEncoder(encoderCfg), os.Stdout, atomicLevel)
sugaredLogger = zap.New(core).Sugar()
}
func SetLevel(level zapcore.Level) {
atomicLevel.SetLevel(level)
}
func Fatal(template string, args ...interface{}) {
sugaredLogger.Fatalf(template, args...)
}
func Error(template string, args ...interface{}) {
sugaredLogger.Errorf(template, args...)
}
func Panic(template string, args ...interface{}) {
sugaredLogger.Panicf(template, args...)
}
func Warn(template string, args ...interface{}) {
sugaredLogger.Warnf(template, args...)
}
func Info(template string, args ...interface{}) {
sugaredLogger.Infof(template, args...)
}
func Debug(template string, args ...interface{}) {
sugaredLogger.Debugf(template, args...)
}