-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlevels.go
78 lines (72 loc) · 1.19 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
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 glo
// Level defines the severity
type Level uint16
// String formats the Level
func (l Level) String() string {
l = levelSnap(l)
return levelNames[l]
}
const (
// Debug severity
Debug Level = 100
// Info severity
Info Level = 200
// Notice severity
Notice Level = 250
// Warning severity
Warning Level = 300
// Error severity
Error Level = 400
// Critical severity
Critical Level = 500
// Alert severity
Alert Level = 550
// Emergency severity
Emergency Level = 600
)
// LevelList incrementally lists severities
var LevelList = []Level{
Debug,
Info,
Notice,
Warning,
Error,
Critical,
Alert,
Emergency,
}
// LevelNames maps a Level to a string
var levelNames = map[Level]string{
Debug: "DEBUG",
Info: "INFO",
Notice: "NOTICE",
Warning: "WARNING",
Error: "ERROR",
Critical: "CRITICAL",
Alert: "ALERT",
Emergency: "EMERGENCY",
}
func levelSnap(in Level) Level {
if in >= Emergency {
return Emergency
}
if in >= Alert {
return Alert
}
if in >= Critical {
return Critical
}
if in >= Error {
return Error
}
if in >= Warning {
return Warning
}
if in >= Notice {
return Notice
}
if in >= Info {
return Info
}
return Debug
}