-
Notifications
You must be signed in to change notification settings - Fork 35
/
logger.go
39 lines (34 loc) · 977 Bytes
/
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
package main
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
// getLoggerVerbosity returns an appropriate logging level based on flags.
func getLoggerVerbosity(verbosity []bool) zapcore.Level {
switch len(verbosity) {
case 0:
return zap.WarnLevel
case 1:
return zap.InfoLevel
default:
return zap.DebugLevel
}
}
func configureLoggerConfig(opts *Options) zap.Config {
loggerConfig := zap.NewDevelopmentConfig()
loggerConfig.EncoderConfig = zapcore.EncoderConfig{
// Keys can be anything except the empty string.
TimeKey: "T",
LevelKey: "L",
NameKey: "N",
CallerKey: "C",
MessageKey: "M",
StacktraceKey: "S",
EncodeLevel: zapcore.CapitalLevelEncoder,
EncodeTime: zapcore.ISO8601TimeEncoder,
EncodeDuration: zapcore.StringDurationEncoder,
}
// Set the logger level based on the command line parsed options.
loggerConfig.Level.SetLevel(getLoggerVerbosity(opts.Verbosity))
return loggerConfig
}