forked from kataras/iris
/
logger.go
101 lines (86 loc) · 2.67 KB
/
logger.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
package config
import (
"github.com/fatih/color"
"github.com/imdario/mergo"
)
import (
"os"
)
// DefaultLoggerPrefix is the prefix (expect the [IRIS]), is empty for now
const DefaultLoggerPrefix = ""
var (
// TimeFormat default time format for any kind of datetime parsing
TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"
)
type (
// Logger contains the full configuration options fields for the Logger
Logger struct {
// Out the (file) writer which the messages/logs will printed to
// Default is os.Stdout
Out *os.File
// Prefix the prefix for each message
// Default is ""
Prefix string
// Disabled default is false
Disabled bool
// foreground colors single SGR Code
// ColorFgDefault the foreground color for the normal message bodies
ColorFgDefault int
// ColorFgInfo the foreground color for info messages
ColorFgInfo int
// ColorFgSuccess the foreground color for success messages
ColorFgSuccess int
// ColorFgWarning the foreground color for warning messages
ColorFgWarning int
// ColorFgDanger the foreground color for error messages
ColorFgDanger int
// OtherFgColor the foreground color for the rest of the message types
ColorFgOther int
// background colors single SGR Code
// ColorBgDefault the background color for the normal messages
ColorBgDefault int
// ColorBgInfo the background color for info messages
ColorBgInfo int
// ColorBgSuccess the background color for success messages
ColorBgSuccess int
// ColorBgWarning the background color for warning messages
ColorBgWarning int
// ColorBgDanger the background color for error messages
ColorBgDanger int
// OtherFgColor the background color for the rest of the message types
ColorBgOther int
// banners are the force printed/written messages, doesn't care about Disabled field
// ColorFgBanner the foreground color for the banner
ColorFgBanner int
}
)
// DefaultLogger returns the default configs for the Logger
func DefaultLogger() Logger {
return Logger{
Out: os.Stdout,
Prefix: "",
Disabled: false,
// foreground colors
ColorFgDefault: int(color.FgHiWhite),
ColorFgInfo: int(color.FgHiCyan),
ColorFgSuccess: int(color.FgHiGreen),
ColorFgWarning: int(color.FgHiMagenta),
ColorFgDanger: int(color.FgHiRed),
ColorFgOther: int(color.FgHiYellow),
// background colors
ColorBgDefault: 0,
ColorBgInfo: 0,
ColorBgSuccess: 0,
ColorBgWarning: 0,
ColorBgDanger: 0,
ColorBgOther: 0,
// banner color
ColorFgBanner: int(color.FgHiBlue),
}
}
// MergeSingle merges the default with the given config and returns the result
func (c Logger) MergeSingle(cfg Logger) (config Logger) {
config = cfg
mergo.Merge(&config, c)
return
}