-
Notifications
You must be signed in to change notification settings - Fork 0
/
logformat.go
63 lines (58 loc) · 1.5 KB
/
logformat.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
package main
import (
"fmt"
"os"
"github.com/logrusorgru/aurora/v4"
"github.com/rs/zerolog"
)
func createFormatter() zerolog.ConsoleWriter {
formatter := zerolog.ConsoleWriter{
Out: os.Stdout,
// Disable timestamp
FormatTimestamp: func(i interface{}) string {
return ""
},
FormatLevel: func(i interface{}) string {
if stringLevel, ok := i.(string); ok {
switch stringLevel {
case zerolog.LevelTraceValue:
return fmt.Sprintf("%s", aurora.Magenta("TRACE"))
case zerolog.LevelDebugValue:
return fmt.Sprintf("%s", aurora.Yellow("DEBUG"))
case zerolog.LevelInfoValue:
return fmt.Sprintf("%s", aurora.Green("INFO "))
case zerolog.LevelWarnValue:
return fmt.Sprintf("%s", aurora.Red("WARN "))
case zerolog.LevelErrorValue:
return fmt.Sprintf("%s", aurora.Red("ERROR").Bold())
case zerolog.LevelFatalValue:
return fmt.Sprintf("%s", aurora.Red("FATAL").Bold())
case zerolog.LevelPanicValue:
return fmt.Sprintf("%s", aurora.Red("PANIC").Bold())
default:
return fmt.Sprintf("%s", i)
}
} else {
return fmt.Sprintf("%s", i)
}
},
FormatFieldName: func(i interface{}) string {
return ""
},
FormatFieldValue: func(i interface{}) string {
return ""
},
FormatErrFieldName: func(i interface{}) string {
return ""
},
FormatErrFieldValue: func(i interface{}) string {
return ""
},
}
return formatter
}
func createTraceFormatter() zerolog.ConsoleWriter {
return zerolog.ConsoleWriter{
Out: os.Stdout,
}
}