-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
42 lines (37 loc) · 1.19 KB
/
Copy pathconfig.go
File metadata and controls
42 lines (37 loc) · 1.19 KB
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
package zapflatencoder
import (
"strconv"
"go.uber.org/zap/zapcore"
)
const (
// EncoderName registered with zap for usage
EncoderName = "flat-encoder"
tokenTab = '\t'
tokenReplacement = `\ufffd`
tokenLineEnding = zapcore.DefaultLineEnding
tokenNamespaceOpen = '{'
tokenNamespaceClose = '}'
tokenArrayOpen = '['
tokenArrayClose = ']'
tokenKeyValueSeparator = '='
tokenStringEnclosed = '"'
)
// ShortColorCallerEncoder encodes caller information with sort path filename and enable color.
func ShortColorCallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder) {
callerStr := caller.TrimmedPath() + ":" + strconv.Itoa(caller.Line)
enc.AppendString(callerStr)
}
// DefaultConfig ...
var DefaultConfig = zapcore.EncoderConfig{
TimeKey: "time",
LevelKey: "level",
NameKey: "logger",
CallerKey: "caller",
MessageKey: "msg",
StacktraceKey: "stacktrace",
LineEnding: zapcore.DefaultLineEnding,
EncodeLevel: zapcore.CapitalColorLevelEncoder,
EncodeTime: zapcore.ISO8601TimeEncoder,
EncodeDuration: zapcore.StringDurationEncoder,
EncodeCaller: ShortColorCallerEncoder,
}