-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlevel.go
More file actions
82 lines (67 loc) · 1.88 KB
/
level.go
File metadata and controls
82 lines (67 loc) · 1.88 KB
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
package log
import "strings"
type Level uint8
const (
/// A special log level used to turn off logging.
Quiet Level = iota
// For pervasive information on states of all elementary constructs.
// Use 'Trace' for in-depth debugging to find problem parts of a function,
// to check values of temporary variables, etc.
Trace
// For detailed system behavior reports and diagnostic messages
// to help to locate problems during development.
Debug
// For general information on the application's work.
// Use 'Info' level in your code so that you could leave it
// 'enabled' even in production. So it is a 'production log level'.
Info
// For indicating small errors, strange situations,
// failures that are automatically handled in a safe manner.
Warn
// For severe failures that affects application's workflow,
// not fatal, however (without forcing app shutdown).
Error
// For producing final messages before application’s death.
Critical
)
var levelText = map[Level]string{
Quiet: "quiet",
Trace: "trace",
Debug: "debug",
Info: "info",
Warn: "warn",
Error: "error",
Critical: "critical",
}
func (l Level) String() string { return levelText[l] }
func (l *Level) UnmarshalYAML(unmarshal func(interface{}) error) error {
v := ""
unmarshal(&v)
*l = NewLevel(v)
return nil
}
func (l Level) MarshalYAML() (interface{}, error) { return l.String(), nil }
func NewLevel(v string) Level {
v = strings.ToLower(v)
v = strings.Replace(v, " ", "-", -1)
v = strings.Replace(v, "_", "-", -1)
v = strings.Replace(v, "(", "", -1)
v = strings.Replace(v, ")", "", -1)
switch v {
case "q", "quiet", "off":
return Quiet
case "t", "trace":
return Trace
case "d", "debug":
return Debug
case "i", "info":
return Info
case "w", "warn", "warning":
return Warn
case "e", "err", "error":
return Error
case "c", "crit", "critical":
return Critical
}
return Quiet
}