-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
44 lines (40 loc) · 1.04 KB
/
log.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
package gobatis
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"time"
)
var (
logger *zap.Logger
)
func init() {
// 自定义zap日志配置
encoderConfig := zapcore.EncoderConfig{
TimeKey: "time",
LevelKey: "level",
NameKey: "logger",
CallerKey: "line",
MessageKey: "message",
StacktraceKey: "stacktrace",
LineEnding: zapcore.DefaultLineEnding,
EncodeLevel: zapcore.LowercaseLevelEncoder, // 小写编码器
EncodeTime: func(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
enc.AppendString(t.Format(time.DateTime))
},
EncodeDuration: zapcore.SecondsDurationEncoder, //
EncodeCaller: zapcore.ShortCallerEncoder, // 全路径编码器
EncodeName: zapcore.FullNameEncoder,
}
cfg := zap.Config{
Encoding: "console",
Level: zap.NewAtomicLevelAt(zap.DebugLevel),
OutputPaths: []string{"stdout"},
ErrorOutputPaths: []string{"stderr"},
EncoderConfig: encoderConfig,
}
var err error
logger, err = cfg.Build()
if err != nil {
panic(err)
}
}