-
Notifications
You must be signed in to change notification settings - Fork 0
/
priority.go
44 lines (39 loc) · 1.05 KB
/
priority.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 log
import "github.com/logrusorgru/aurora"
// Priority is a type alias for logging priority levels.
type Priority uint8
// Log Priority levels are listed here as constants for convenience.
const (
LevelPanic Priority = iota
LevelFatal
LevelError
LevelWarn
LevelInfo
LevelDebug
)
// priorityShowValues is an array that contains Priority string representations.
// Notice, that all strings here are exactly 5 chars long so as to be perfectly
// aligned when printed.
var priorityShowValues = [6]struct {
text string
color func(interface{}) aurora.Value
}{
{"PANIC", aurora.Magenta},
{"FATAL", aurora.Magenta},
{"ERROR", aurora.Red},
{"WARN ", aurora.Yellow},
{"INFO ", aurora.Green},
{"DEBUG", aurora.Blue},
}
// show function returns Priority flag as a string colored depending on the
// color argument passed in.
func (p Priority) show(color bool) interface{} {
if int(p) >= len(priorityShowValues) {
panic("cannot show unknown Priority")
}
value := priorityShowValues[p]
if color {
return value.color(value.text)
}
return value.text
}