-
Notifications
You must be signed in to change notification settings - Fork 0
/
development.go
46 lines (41 loc) · 1.11 KB
/
development.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
package log
import (
"time"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func NewDevelopmentEncoderConfig() zapcore.EncoderConfig {
return zapcore.EncoderConfig{
TimeKey: "T",
LevelKey: "L",
NameKey: "N",
CallerKey: "C",
MessageKey: "M",
StacktraceKey: "S",
LineEnding: zapcore.DefaultLineEnding,
EncodeLevel: zapcore.CapitalColorLevelEncoder,
EncodeTime: timeEncoder,
EncodeDuration: zapcore.StringDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
}
}
func timeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
enc.AppendString(t.Format("15:04:05"))
}
func NewDevelopmentConfig() zap.Config {
return zap.Config{
Level: zap.NewAtomicLevelAt(zap.DebugLevel),
Development: true,
DisableCaller: false,
DisableStacktrace: true,
Sampling: &zap.SamplingConfig{
Initial: 100,
Thereafter: 100,
},
Encoding: "console",
EncoderConfig: NewDevelopmentEncoderConfig(),
OutputPaths: []string{"stderr"},
ErrorOutputPaths: []string{"stderr"},
InitialFields: map[string]interface{}{},
}
}