-
Notifications
You must be signed in to change notification settings - Fork 232
/
level.go
54 lines (48 loc) · 1.26 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
package logger
import "strings"
// Level is the level at which a logger is configured. All messages sent
// to a level which is below the current level are filtered.
type Level uint32
// Level constants.
const (
LevelTrace Level = iota
LevelDebug
LevelInfo
LevelWarn
LevelError
LevelCritical
LevelOff
)
// levelStrs defines the human-readable names for each logging level.
var levelStrs = [...]string{"TRC", "DBG", "INF", "WRN", "ERR", "CRT", "OFF"}
// LevelFromString returns a level based on the input string s. If the input
// can't be interpreted as a valid log level, the info level and false is
// returned.
func LevelFromString(s string) (l Level, ok bool) {
switch strings.ToLower(s) {
case "trace", "trc":
return LevelTrace, true
case "debug", "dbg":
return LevelDebug, true
case "info", "inf":
return LevelInfo, true
case "warn", "wrn":
return LevelWarn, true
case "error", "err":
return LevelError, true
case "critical", "crt":
return LevelCritical, true
case "off":
return LevelOff, true
default:
return LevelInfo, false
}
}
// String returns the tag of the logger used in log messages, or "OFF" if
// the level will not produce any log output.
func (l Level) String() string {
if l >= LevelOff {
return "OFF"
}
return levelStrs[l]
}