-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor.go
49 lines (45 loc) · 1.14 KB
/
color.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
//go:build !windows
package olog
const (
Reset = "\033[0m"
Red = "\033[31m"
RedBold = "\033[1;31m"
Green = "\033[32m"
GreenBold = "\033[1;32m"
Yellow = "\033[33m"
Blue = "\033[34m"
BlueBold = "\033[1;34m"
Purple = "\033[35m"
Cyan = "\033[36m"
Gray = "\033[37m"
White = "\033[97m"
)
type stringWriter interface {
WriteString(string) (int, error)
}
// writeLevelWithColor takes in a level of logging and a tag string, and returns a string that
// contains the tag string wrapped with an ANSI color code to represent the level of logging.
// The returned string will have different colors depending on the level of logging.
func writeLevelWithColor(level Level, tag string, w stringWriter) {
switch level {
case FATAL:
_, _ = w.WriteString(RedBold)
case ERROR:
_, _ = w.WriteString(Red)
case WARN:
_, _ = w.WriteString(Yellow)
case NOTICE:
_, _ = w.WriteString(Blue)
case INFO:
_, _ = w.WriteString(Green)
case DEBUG:
_, _ = w.WriteString(Gray)
case TRACE:
_, _ = w.WriteString(Cyan)
default:
_, _ = w.WriteString(tag)
return
}
_, _ = w.WriteString(tag)
_, _ = w.WriteString(Reset)
}