-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel.go
50 lines (44 loc) · 847 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
package mo
import "fmt"
type Level int8
func (l Level) String() string {
if b, err := l.MarshalText(); err == nil {
return string(b)
} else {
return "unknown"
}
}
func (l Level) MarshalText() ([]byte, error) {
switch l {
case LEVEL_NONE:
return []byte("none"), nil
case LEVEL_ERROR:
return []byte("error"), nil
case LEVEL_WARN:
return []byte("warn"), nil
case LEVEL_INFO:
return []byte("info"), nil
case LEVEL_LOG:
return []byte("log"), nil
case LEVEL_SUCCESS:
return []byte("success"), nil
case LEVEL_DEBUG:
return []byte("debug"), nil
case LEVEL_ALL:
return []byte("all"), nil
}
return []byte(fmt.Sprintf("%d", l)), nil
}
const (
LEVEL_NONE Level = iota
LEVEL_ERROR
LEVEL_WARN
LEVEL_INFO
LEVEL_LOG
LEVEL_SUCCESS
LEVEL_DEBUG
LEVEL_ALL
)
func isEnableLevel(a Level, b Level) bool {
return b <= a
}