-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogLevel.go
More file actions
58 lines (50 loc) · 916 Bytes
/
logLevel.go
File metadata and controls
58 lines (50 loc) · 916 Bytes
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"
"math"
)
type Level string
const (
ALL Level = "all"
TRACE Level = "trace"
DEBUG Level = "debug"
INFO Level = "info"
WARN Level = "warn"
ERROR Level = "error"
FATAL Level = "fatal"
NONE Level = "none"
)
var (
LogLevelPriorities = map[Level] uint {
ALL: 0,
TRACE: 1000,
DEBUG: 2000,
INFO: 3000,
WARN: 4000,
ERROR: 5000,
FATAL: 6000,
NONE: math.MaxUint32,
}
LogLevelColors = map[Level] string {
ALL: "grey",
TRACE: "blue",
DEBUG: "cyan",
INFO: "green",
WARN: "yellow",
ERROR: "red",
FATAL: "magenta",
NONE: "grey",
}
)
func GetLevel(level Level, defaultLevel Level) Level {
if level != "" {
return level
}
return defaultLevel
}
func IsLevelEnabled(level Level, targetLevel Level) bool {
return LogLevelPriorities[level] <= LogLevelPriorities[targetLevel]
}
func (l Level) String() string {
return strings.ToUpper(string(l))
}