-
Notifications
You must be signed in to change notification settings - Fork 4
/
level.go
58 lines (53 loc) · 1003 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package log
import "strings"
// Log levels from low to high.
// NOTE: FATAL is the highest, NOTSET is the lowest.
const (
NOTSET Level = iota
DEBUG
INFO
WARN
ERROR
FATA
)
// LevelFromString parses string to Level.
// NOTSET is returned if the given string can not be recognized.
func LevelFromString(s string) Level {
switch strings.TrimSpace(strings.ToUpper(s)) {
case "DEBUG", "D":
return DEBUG
case "INFO", "I":
return INFO
case "WARN", "WARNING", "W":
return WARN
case "ERROR", "E":
return ERROR
case "FATA", "FATAL", "F":
return FATA
case "NOTSET", "NOT SET", "N":
fallthrough
default:
return NOTSET
}
}
// Level represents level of logging.
type Level int32
// String returns the string representation of Level.
func (l Level) String() string {
switch l {
case DEBUG:
return "DEBUG"
case INFO:
return "INFO"
case WARN:
return "WARN"
case ERROR:
return "ERROR"
case FATA:
return "FATA"
case NOTSET:
fallthrough
default:
return "NOT SET"
}
}