-
Notifications
You must be signed in to change notification settings - Fork 10
/
logger.go
40 lines (36 loc) · 1.09 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
package pcap
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var zapConfig zap.Config
func init() {
zapConfig = zap.Config{
Level: zap.NewAtomicLevelAt(zap.InfoLevel),
DisableCaller: true,
DisableStacktrace: true,
Encoding: "json",
EncoderConfig: zapcore.EncoderConfig{
TimeKey: "timestamp",
LevelKey: "level",
NameKey: "logger",
CallerKey: "caller",
MessageKey: "msg",
LineEnding: zapcore.DefaultLineEnding,
EncodeLevel: zapcore.LowercaseLevelEncoder,
EncodeTime: zapcore.RFC3339TimeEncoder,
EncodeDuration: zapcore.SecondsDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
},
OutputPaths: []string{"stderr"},
ErrorOutputPaths: []string{"stderr"},
}
zap.ReplaceGlobals(zap.Must(zapConfig.Build()))
}
func SetLogLevel(log *zap.Logger, logLevel string) {
if level, levelErr := zap.ParseAtomicLevel(logLevel); levelErr == nil {
zapConfig.Level.SetLevel(level.Level())
} else {
log.Warn("unable to parse log level, remaining at default log level", zap.Error(levelErr))
}
}