-
Notifications
You must be signed in to change notification settings - Fork 1
/
level.go
42 lines (36 loc) · 902 Bytes
/
level.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
package logging
import "go.uber.org/zap/zapcore"
type LogLevel string
const (
levelDebug LogLevel = "DEBUG"
levelInfo LogLevel = "INFO"
levelWarning LogLevel = "WARNING"
levelError LogLevel = "ERROR"
)
func levelToZapLevel(level LogLevel) zapcore.Level {
switch level {
case levelDebug:
return zapcore.DebugLevel
case levelInfo:
return zapcore.InfoLevel
case levelWarning:
return zapcore.WarnLevel
case levelError:
return zapcore.ErrorLevel
}
return zapcore.DebugLevel
}
func levelEncoder() zapcore.LevelEncoder {
return func(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder) {
switch l {
case zapcore.DebugLevel:
enc.AppendString(string(levelDebug))
case zapcore.InfoLevel:
enc.AppendString(string(levelInfo))
case zapcore.WarnLevel:
enc.AppendString(string(levelWarning))
case zapcore.ErrorLevel:
enc.AppendString(string(levelError))
}
}
}