-
Notifications
You must be signed in to change notification settings - Fork 42
/
level.go
162 lines (154 loc) · 2.93 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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package log
// Level defines log levels.
type Level int32
const (
// TraceLevel defines trace log level.
TraceLevel Level = -1
// DebugLevel defines debug log level.
DebugLevel Level = 0
// InfoLevel defines info log level.
InfoLevel Level = 1
// WarnLevel defines warn log level.
WarnLevel Level = 2
// ErrorLevel defines error log level.
ErrorLevel Level = 3
// FatalLevel defines fatal log level.
FatalLevel Level = 4
// PanicLevel defines panic log level.
PanicLevel Level = 5
// NoLevel defines an absent log level.
noLevel Level = 6
)
// Lower return lowe case string of Level
func (l Level) Lower() (s string) {
switch l {
case TraceLevel:
s = "trace"
case DebugLevel:
s = "debug"
case InfoLevel:
s = "info"
case WarnLevel:
s = "warn"
case ErrorLevel:
s = "error"
case FatalLevel:
s = "fatal"
case PanicLevel:
s = "panic"
default:
s = "????"
}
return
}
// Upper return upper case string of Level
func (l Level) Upper() (s string) {
switch l {
case TraceLevel:
s = "TRACE"
case DebugLevel:
s = "DEBUG"
case InfoLevel:
s = "INFO"
case WarnLevel:
s = "WARN"
case ErrorLevel:
s = "ERROR"
case FatalLevel:
s = "FATAL"
case PanicLevel:
s = "PANIC"
default:
s = "????"
}
return
}
// Title return title case string of Level
func (l Level) Title() (s string) {
switch l {
case TraceLevel:
s = "Trace"
case DebugLevel:
s = "Debug"
case InfoLevel:
s = "Info"
case WarnLevel:
s = "Warn"
case ErrorLevel:
s = "Error"
case FatalLevel:
s = "Fatal"
case PanicLevel:
s = "Panic"
default:
s = "????"
}
return
}
// Three return three letters of Level
func (l Level) Three() (s string) {
switch l {
case TraceLevel:
s = "TRC"
case DebugLevel:
s = "DBG"
case InfoLevel:
s = "INF"
case WarnLevel:
s = "WRN"
case ErrorLevel:
s = "ERR"
case FatalLevel:
s = "FTL"
case PanicLevel:
s = "PNC"
default:
s = "???"
}
return
}
// First return first upper letter of Level
func (l Level) First() (s string) {
switch l {
case TraceLevel:
s = "T"
case DebugLevel:
s = "D"
case InfoLevel:
s = "I"
case WarnLevel:
s = "W"
case ErrorLevel:
s = "E"
case FatalLevel:
s = "F"
case PanicLevel:
s = "P"
default:
s = "?"
}
return
}
// ParseLevel converts a level string into a log Level value.
// returns an error if the input string does not match known values.
func ParseLevel(s string) (level Level) {
switch s {
case "t", "trace", "Trace", "TRACE", "T", "TRC":
level = TraceLevel
case "d", "debug", "Debug", "DEBUG", "D", "DBG":
level = DebugLevel
case "i", "info", "Info", "INFO", "I", "INF":
level = InfoLevel
case "w", "warn", "Warn", "WARN", "warning", "Warning", "WARNING", "W", "WRN":
level = WarnLevel
case "e", "error", "Error", "ERROR", "E", "ERR":
level = ErrorLevel
case "f", "fatal", "Fatal", "FATAL", "F", "FTL":
level = FatalLevel
case "p", "panic", "Panic", "PANIC", "P", "PNC":
level = PanicLevel
default:
level = noLevel
}
return
}