-
Notifications
You must be signed in to change notification settings - Fork 1
/
level.go
44 lines (37 loc) · 821 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
package logger
import "strings"
type Level int
const (
TraceLevel Level = iota
DebugLevel
InfoLevel
WarnLevel
ErrorLevel
FatalLevel
PanicLevel
)
var (
levelText = []string{"TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL", "PANIC"}
toLevel = map[string]Level{
"TRACE": TraceLevel,
"DEBUG": DebugLevel,
"INFO": InfoLevel,
"WARN": WarnLevel,
"WARNING": WarnLevel,
"ERR": ErrorLevel,
"ERROR": ErrorLevel,
"FATAL": FatalLevel,
"PANIC": PanicLevel,
}
)
// ToLevel map text of level to log.Level
// Trace, Debug, Info, Warn or Warning, Error or Err, Fatal, Panic
func ToLevel(level string) (Level, bool) {
if l, ok := toLevel[strings.ToUpper(level)]; ok {
return l, true
}
return TraceLevel, false
}
func LevelText(level Level) string {
return levelText[level]
}