-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.go
40 lines (36 loc) · 931 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
40
package main
import "go.uber.org/zap"
var (
logger *zap.SugaredLogger
loggerConfig = zap.Config{
Level: zap.NewAtomicLevelAt(zap.ErrorLevel),
Development: false,
DisableCaller: true,
Encoding: "console",
EncoderConfig: zap.NewDevelopmentEncoderConfig(),
OutputPaths: []string{"stdout"},
ErrorOutputPaths: []string{"stderr"},
}
)
func init() {
basicLogger, err := loggerConfig.Build()
if err != nil {
panic("cannot open logger")
}
logger = basicLogger.Sugar()
defer logger.Sync()
}
func setLogLevel(level string) {
switch level {
case "error":
loggerConfig.Level.SetLevel(zap.ErrorLevel)
case "warn":
loggerConfig.Level.SetLevel(zap.WarnLevel)
case "info":
loggerConfig.Level.SetLevel(zap.InfoLevel)
case "verbose":
loggerConfig.Level.SetLevel(zap.DebugLevel)
default:
panic("wrong log level, only error, warn, info and verbose are support")
}
}