-
Notifications
You must be signed in to change notification settings - Fork 2
/
zap.go
51 lines (43 loc) · 1.08 KB
/
zap.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
47
48
49
50
51
package log
import (
"log"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
// P is a plain zap logger
var P *zap.Logger
// Config is the logger config used for P
var Config zap.Config
func init() {
var err error
Config = zap.Config{
Level: zap.NewAtomicLevelAt(zap.DebugLevel),
Development: false,
Sampling: &zap.SamplingConfig{
Initial: 100,
Thereafter: 100,
},
Encoding: "json",
EncoderConfig: zapcore.EncoderConfig{
TimeKey: "@",
LevelKey: "level",
NameKey: "logger",
CallerKey: "caller",
MessageKey: "msg",
StacktraceKey: "stacktrace",
LineEnding: zapcore.DefaultLineEnding,
EncodeLevel: zapcore.LowercaseLevelEncoder,
EncodeTime: zapcore.ISO8601TimeEncoder,
EncodeDuration: zapcore.StringDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
},
OutputPaths: []string{"stderr"},
ErrorOutputPaths: []string{"stderr"},
}
P, err = Config.Build()
if err != nil {
log.Fatalf("failed to initialize zap logger: %v", err)
}
P.Info("Zap logger started")
_ = P.Sync()
}