forked from morita-kuma/golog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloglevel.go
85 lines (73 loc) · 1.5 KB
/
loglevel.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
79
80
81
82
83
84
85
package golog
import "sort"
// LogLevel
type LogLevel int32
// LogLevel Constants
const (
LogLevel_TRACE LogLevel = 0
LogLevel_DEBUG LogLevel = 1
LogLevel_INFO LogLevel = 2
LogLevel_WARN LogLevel = 3
LogLevel_ERROR LogLevel = 4
LogLevel_FATAL LogLevel = 5
)
// TypeVal
func (logLevel LogLevel) TypeVal() int32 {
return int32(logLevel)
}
// String
func (logLevel LogLevel) String() string {
switch logLevel {
case LogLevel_TRACE :
return "[TRACE]"
case LogLevel_DEBUG:
return "[DEBUG]"
case LogLevel_INFO:
return "[INFO]"
case LogLevel_WARN:
return "[WARN]"
case LogLevel_ERROR:
return "[ERROR]"
case LogLevel_FATAL:
return "[FATAL]"
default:
return "[UNKNOWN]"
}
}
// TODO go generate
var logLevelMap = map[int32]LogLevel {
0 : LogLevel_TRACE,
1 : LogLevel_DEBUG,
2 : LogLevel_INFO,
3 : LogLevel_WARN,
4 : LogLevel_ERROR,
5 : LogLevel_FATAL,
}
// LogLevels
type LogLevels []LogLevel
// Contains
func (levels LogLevels) Contains (logLevel LogLevel) bool {
for _, level := range levels {
if level == logLevel {
return true
}
}
return false
}
// Len implements the Sort interface
func (levels LogLevels) Len() int {
return len(levels)
}
// Swap implements the Sort interface
func (levels LogLevels) Swap(i, j int) {
levels[i], levels[j] = levels[j], levels[i]
}
// Less implements the Sort interface
func (levels LogLevels) Less(i, j int) bool {
return levels[i] < levels[j]
}
// Sort by ID ASC
func (levels LogLevels) SortAsc() LogLevels {
sort.Sort(levels)
return levels
}