-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathlevel.go
57 lines (52 loc) · 1.07 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
package log
import "strings"
// Level is a logging level.
type Level int32
const (
// DebugLevel is the debug level.
DebugLevel Level = iota - 1
// InfoLevel is the info level.
InfoLevel
// WarnLevel is the warn level.
WarnLevel
// ErrorLevel is the error level.
ErrorLevel
// FatalLevel is the fatal level.
FatalLevel
// noLevel is used with log.Print.
noLevel
)
// String returns the string representation of the level.
func (l Level) String() string {
switch l {
case DebugLevel:
return "debug"
case InfoLevel:
return "info"
case WarnLevel:
return "warn"
case ErrorLevel:
return "error"
case FatalLevel:
return "fatal"
default:
return ""
}
}
// ParseLevel converts level in string to Level type. Default level is InfoLevel.
func ParseLevel(level string) Level {
switch strings.ToLower(level) {
case DebugLevel.String():
return DebugLevel
case InfoLevel.String():
return InfoLevel
case WarnLevel.String():
return WarnLevel
case ErrorLevel.String():
return ErrorLevel
case FatalLevel.String():
return FatalLevel
default:
return InfoLevel
}
}