-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.go
69 lines (56 loc) · 1.33 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
package log
// Allowed log level constants.
const (
FATAL Level = "FATAL"
ERROR Level = "ERROR"
WARN Level = "WARNING"
INFO Level = "INFO"
DEBUG Level = "DEBUG"
TRACE Level = "TRACE"
)
// Level identifies the logging level.
type Level string
// Levels contains active log levels.
type Levels map[Level]bool
// Set sets active log levels.
func (l *Levels) Set(levels ...Level) []Level {
var result = make(map[Level]bool, len(levels))
for _, level := range levels {
result[level] = true
}
*l = result
return activeLevels(*l)
}
// Add adds new levels to the list of active logging levels.
func (l *Levels) Add(levels ...Level) []Level {
for _, level := range levels {
(*l)[level] = true
}
return activeLevels(*l)
}
// Delete removes the specified logging levels from
// the list of active logging levels.
func (l *Levels) Delete(levels ...Level) []Level {
for _, level := range levels {
(*l)[level] = false
}
return activeLevels(*l)
}
// All returns true if all logging levels are supported.
func (l *Levels) All(levels ...Level) bool {
for _, level := range levels {
if v := (*l)[level]; !v {
return false
}
}
return true
}
// Any returns true if any logging level is supported.
func (l *Levels) Any(levels ...Level) bool {
for _, level := range levels {
if v := (*l)[level]; v {
return true
}
}
return false
}