-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.go
46 lines (41 loc) · 1.02 KB
/
setup.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
package zapsetup
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var (
rootLogger = NewLogger()
)
func RootLogger() *LoggerX {
return rootLogger
}
func NewLogger(opts ...Option) *LoggerX {
newCfg := defaultConfig()
for _, opt := range opts {
opt(newCfg)
}
return newLoggerX(newCfg)
}
func defaultConfig() *zap.Config {
return &zap.Config{
Level: zap.NewAtomicLevelAt(zapcore.InfoLevel),
Development: false,
Sampling: nil,
Encoding: "console",
OutputPaths: []string{"stdout"},
ErrorOutputPaths: []string{"stderr"},
EncoderConfig: zapcore.EncoderConfig{
TimeKey: "ts",
LevelKey: "level",
NameKey: "logger",
CallerKey: "caller",
MessageKey: "msg",
StacktraceKey: "stacktrace",
LineEnding: zapcore.DefaultLineEnding,
EncodeLevel: zapcore.LowercaseLevelEncoder,
EncodeTime: zapcore.ISO8601TimeEncoder,
EncodeDuration: zapcore.SecondsDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
},
}
}