-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayouts.go
More file actions
58 lines (47 loc) · 1.39 KB
/
layouts.go
File metadata and controls
58 lines (47 loc) · 1.39 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
package log
import (
"fmt"
"runtime"
"github.com/mattn/go-colorable"
)
var Output = colorable.NewColorableStdout()
var styles map[string] []int = map[string] []int {
"bold": { 1, 22 },
"italic": { 3, 23 },
"underline": { 4, 24 },
"inverse": { 7, 27 },
"white": { 37, 39 },
"grey": { 90, 39 },
"black": { 90, 39 },
"blue": { 34, 39 },
"cyan": { 36, 39 },
"green": { 32, 39 },
"magenta": {35, 39 },
"red": { 91, 39 },
"yellow": { 33, 39 },
}
func colorStart(color string) string {
if color != "" {
return fmt.Sprintf("\x1B[%vm", styles[color][0])
}
return ""
}
func colorEnd(color string) string {
if color != "" {
if runtime.GOOS == "windows" {
return fmt.Sprintf("\x1B[0m")
} else {
return fmt.Sprintf("\x1B[%vm", styles[color][1])
}
}
return ""
}
func colorize(str string, color string) string {
return colorStart(color) + str + colorEnd(color)
}
func basicLayout(event *LoggingEvent) string {
return fmt.Sprintf("[%v] [%v] %v - ", event.StartTime.Format("2006-01-02T15:04:05.999-07:00"), event.Level.String(), event.Category) + fmt.Sprintf(event.Data[0].(string), event.Data[1:]...)
}
func colorizedLayout(event *LoggingEvent) string {
return colorize(fmt.Sprintf("[%v] [%v] %v - ", event.StartTime.Format("2006-01-02T15:04:05.999-07:00"), event.Level.String(), event.Category), LogLevelColors[event.Level]) + fmt.Sprintf(event.Data[0].(string), event.Data[1:]...)
}