-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
level.go
59 lines (54 loc) · 952 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
51
52
53
54
55
56
57
58
59
package log
import (
E "github.com/sagernet/sing/common/exceptions"
)
type Level = uint8
const (
LevelPanic Level = iota
LevelFatal
LevelError
LevelWarn
LevelInfo
LevelDebug
LevelTrace
)
func FormatLevel(level Level) string {
switch level {
case LevelTrace:
return "trace"
case LevelDebug:
return "debug"
case LevelInfo:
return "info"
case LevelWarn:
return "warn"
case LevelError:
return "error"
case LevelFatal:
return "fatal"
case LevelPanic:
return "panic"
default:
return "unknown"
}
}
func ParseLevel(level string) (Level, error) {
switch level {
case "trace":
return LevelTrace, nil
case "debug":
return LevelDebug, nil
case "info":
return LevelInfo, nil
case "warn", "warning":
return LevelWarn, nil
case "error":
return LevelError, nil
case "fatal":
return LevelFatal, nil
case "panic":
return LevelPanic, nil
default:
return LevelTrace, E.New("unknown log level: ", level)
}
}