-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.go
76 lines (70 loc) · 1.11 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
70
71
72
73
74
75
76
package commonlog
import (
"fmt"
)
//
// Level
//
type Level int
const (
None Level = 0
Critical Level = 1
Error Level = 2
Warning Level = 3
Notice Level = 4
Info Level = 5
Debug Level = 6
)
// ([fmt.Stringify] interface)
func (self Level) String() string {
switch self {
case None:
return "None"
case Critical:
return "Critical"
case Error:
return "Error"
case Warning:
return "Warning"
case Notice:
return "Notice"
case Info:
return "Info"
case Debug:
return "Debug"
default:
panic(fmt.Sprintf("unsupported log level: %d", self))
}
}
// Translates a verbosity number to a maximum loggable level as
// follows:
//
// - -4 and below: [None]
// - -3: [Critical]
// - -2: [Error]
// - -1: [Warning]
// - 0: [Notice]
// - 1: [Info]
// - 2 and above: [Debug]
func VerbosityToMaxLevel(verbosity int) Level {
if verbosity < -4 {
return None
} else {
switch verbosity {
case -4:
return None
case -3:
return Critical
case -2:
return Error
case -1:
return Warning
case 0:
return Notice
case 1:
return Info
default:
return Debug
}
}
}