-
Notifications
You must be signed in to change notification settings - Fork 3
/
levels.go
46 lines (39 loc) · 1.13 KB
/
levels.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 (
"strings"
"go.uber.org/zap/zapcore"
)
type Level string
const (
LevelDebug Level = "debug"
LevelInfo Level = "info"
LevelWarn Level = "warn"
LevelError Level = "error"
// LevelNone silences all log output.
LevelNone Level = "none"
)
// Parse parses the given level string as a supported output format, while trying to
// maintain some degree of back-compat with the intent of previously supported log levels.
//
// This is exported only for internal use.
func (l Level) Parse() zapcore.Level {
switch Level(strings.ToLower(string(l))) {
case LevelDebug, "dbug":
return zapcore.DebugLevel
case LevelInfo:
return zapcore.InfoLevel
case LevelWarn:
return zapcore.WarnLevel
case LevelError, "eror",
// We do not want to introduce 'Critical' support yet, since there are already an
// abundance of log levels. Users of 'Critical' should just use 'Error' instead.
"crit":
return zapcore.ErrorLevel
case LevelNone:
// Logger does not export anything at the fatal level, so this effectively
// silences all output.
return zapcore.FatalLevel
}
// Quietly fall back to warn
return zapcore.WarnLevel
}