-
Notifications
You must be signed in to change notification settings - Fork 90
/
logger.go
74 lines (59 loc) · 1.29 KB
/
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package logger
import (
"os"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var log *zap.Logger
var atom zap.AtomicLevel
func init() {
atom = zap.NewAtomicLevel()
atom.SetLevel(zapcore.InfoLevel)
encoderCfg := zap.NewProductionEncoderConfig()
encoderCfg.EncodeTime = zapcore.RFC3339TimeEncoder
l := zap.New(zapcore.NewCore(
zapcore.NewJSONEncoder(encoderCfg),
zapcore.Lock(os.Stdout),
atom,
))
defer l.Sync()
log = l
}
func SetDebug() {
atom.SetLevel(zapcore.DebugLevel)
}
func Error(err error) {
defer log.Sync()
sugar := log.Sugar()
sugar.Error(err)
}
func Errorf(template string, args ...interface{}) {
defer log.Sync()
sugar := log.Sugar()
sugar.Errorf(template, args...)
}
func Info(msg string, fields ...zap.Field) {
defer log.Sync()
sugar := log.Sugar()
sugar.Info(msg, fields)
}
func Infof(template string, args ...interface{}) {
defer log.Sync()
sugar := log.Sugar()
sugar.Infof(template, args...)
}
func Debug(msg string, fields ...zap.Field) {
defer log.Sync()
sugar := log.Sugar()
sugar.Debug(msg, fields)
}
func Debugf(template string, args ...interface{}) {
defer log.Sync()
sugar := log.Sugar()
sugar.Debugf(template, args...)
}
func Warnf(template string, args ...interface{}) {
defer log.Sync()
sugar := log.Sugar()
sugar.Warnf(template, args...)
}