-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.go
78 lines (72 loc) · 1.94 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package soba
// Level define an entry priority.
type Level uint8
const (
// UnknownLevel represents an unsupported level.
UnknownLevel = Level(iota)
// NoLevel is a no-op entry: the logger is disabled.
NoLevel
// ErrorLevel logs are high-priority. If an application is running smoothly,
// no error should be generated.
ErrorLevel
// WarnLevel is a non-critical entries that deserve eyes.
WarnLevel
// InfoLevel is the default logging priority: general operational entries about what's going on inside the
// application.
InfoLevel
// DebugLevel level. Usually only enabled when debugging. Very verbose logging
DebugLevel
)
const (
strNoLevel = "never"
strNoLevelNo = "no"
strNoLevelNone = "none"
strNoLevelDisable = "disable"
strNoLevelDisabled = "disabled"
strUnknownLevel = "unknown"
strVerboseLevel = "verbose"
strDebugLevel = "debug"
strInfoLevel = "info"
strWarnLevel = "warning"
strShortWarnLevel = "warn"
strErrorLevel = "error"
)
// Convert the Level to a string.
func (level Level) String() string {
switch level {
case DebugLevel:
return strDebugLevel
case InfoLevel:
return strInfoLevel
case WarnLevel:
return strWarnLevel
case ErrorLevel:
return strErrorLevel
case NoLevel:
return strNoLevel
default:
return strUnknownLevel
}
}
// ParseLevel takes a string level and returns the log level constant.
func ParseLevel(level string) (Level, bool) {
switch level {
case strErrorLevel:
return ErrorLevel, true
case strWarnLevel, strShortWarnLevel:
return WarnLevel, true
case strInfoLevel:
return InfoLevel, true
case strDebugLevel, strVerboseLevel:
return DebugLevel, true
case strNoLevel, strNoLevelNo, strNoLevelNone, strNoLevelDisable, strNoLevelDisabled:
return NoLevel, true
default:
return UnknownLevel, false
}
}
// IsLevelNameValid verify that a level name is allowed.
func IsLevelNameValid(level string) bool {
_, ok := ParseLevel(level)
return ok
}