-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel.go
55 lines (48 loc) · 966 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
package log
type Level int
const (
Disabled Level = iota
Debug
Info
Warning
Error
)
func (l Level) String() string {
switch l {
case Error:
return "ERROR"
case Warning:
return "WARNING"
case Info:
return "INFO"
case Debug:
return "DEBUG"
case Disabled:
return "DISABLED"
default:
return "UNKNOWN"
}
}
// IsEnabled return true if l is above or at the same level as threshold.
// If threshold is Disabled or is below l then returns false.
func (l Level) IsEnabled(threshold Level) bool {
if threshold == Disabled {
return false
}
return l >= threshold
}
func levelFromString(str string) (Level, error) {
switch str {
case "error", "ERROR", "Error":
return Error, nil
case "warning", "WARNING", "Warning":
return Warning, nil
case "info", "INFO", "Info":
return Info, nil
case "debug", "DEBUG", "Debug":
return Debug, nil
case "disabled", "DISABLED", "Disabled", "":
return Disabled, nil
}
return 0, ErrBadLevel
}