-
Notifications
You must be signed in to change notification settings - Fork 3
/
log.go
35 lines (32 loc) · 877 Bytes
/
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
package THz
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func (thz *THz) SetLog(log *zap.Logger) { thz.log = log }
func (thz *THz) SetZapLog(level zapcore.Level) {
config := zap.Config{
Level: zap.NewAtomicLevelAt(level),
Development: true,
Encoding: "console",
EncoderConfig: zapcore.EncoderConfig{
MessageKey: "msg",
LevelKey: "level",
TimeKey: "ts",
NameKey: "logger",
CallerKey: "caller",
LineEnding: zapcore.DefaultLineEnding,
EncodeLevel: zapcore.LowercaseLevelEncoder,
EncodeTime: zapcore.ISO8601TimeEncoder,
EncodeDuration: zapcore.SecondsDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
},
OutputPaths: []string{"stdout"},
ErrorOutputPaths: []string{"stderr"},
}
log, err := config.Build()
if err != nil {
panic(err)
}
thz.log = log
}