forked from phuslu/log
-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.go
69 lines (65 loc) · 1.48 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
package log
// Level defines log levels.
type Level uint32
const (
// TraceLevel defines trace log level.
TraceLevel Level = 1
// DebugLevel defines debug log level.
DebugLevel Level = 2
// InfoLevel defines info log level.
InfoLevel Level = 3
// WarnLevel defines warn log level.
WarnLevel Level = 4
// ErrorLevel defines error log level.
ErrorLevel Level = 5
// FatalLevel defines fatal log level.
FatalLevel Level = 6
// PanicLevel defines panic log level.
PanicLevel Level = 7
// NoLevel defines an absent log level.
noLevel Level = 8
)
// String return lowe case string of Level
func (l Level) String() (s string) {
switch l {
case TraceLevel:
s = "trace"
case DebugLevel:
s = "debug"
case InfoLevel:
s = "info"
case WarnLevel:
s = "warn"
case ErrorLevel:
s = "error"
case FatalLevel:
s = "fatal"
case PanicLevel:
s = "panic"
default:
s = "????"
}
return
}
// ParseLevel converts a level string into a log Level value.
func ParseLevel(s string) (level Level) {
switch s {
case "trace", "Trace", "TRACE", "TRC":
level = TraceLevel
case "debug", "Debug", "DEBUG", "DBG":
level = DebugLevel
case "info", "Info", "INFO", "INF":
level = InfoLevel
case "warn", "Warn", "WARN", "warning", "Warning", "WARNING", "WRN":
level = WarnLevel
case "error", "Error", "ERROR", "ERR":
level = ErrorLevel
case "fatal", "Fatal", "FATAL", "FTL":
level = FatalLevel
case "panic", "Panic", "PANIC", "PNC":
level = PanicLevel
default:
level = noLevel
}
return
}