-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger_options.go
168 lines (150 loc) · 4.32 KB
/
logger_options.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package options
import (
"github.com/ereb-or-od/kenobi-logger/pkg/enumeration"
)
var (
defaultEncoding = "json"
defaultOutputPaths = []string{"stdout"}
defaultErrorOutputPaths = []string{"stdout"}
defaultLoggingLevel = "DEBUG"
defaultTimeKey = "timestamp"
defaultLevelKey = "severity"
defaultNameKey = "default-logger"
defaultCallerKey = "caller"
defaultMessageKey = "message"
defaultStackTraceKey = "stacktrace"
defaultFunctionKey = "method"
defaultEncodeLevel = enumeration.Lowercase
defaultEncodeTime = enumeration.RFC3339
defaultEncodeDuration = enumeration.MillisecondDuration
defaultEncodeCaller = enumeration.ShortestFunctionName
)
type LoggerOptions struct {
DefaultParameters map[string]interface{}
Development bool
Encoding string
OutputPaths []string
ErrorOutputPaths []string
Level string
TimeKey string
LevelKey string
NameKey string
CallerKey string
StackTraceKey string
MessageKey string
FunctionKey string
EncodeLevel *enumeration.EncodeLevel
EncodeTime *enumeration.EncodeTime
EncodeDuration *enumeration.EncodeDuration
EncodeCaller *enumeration.EncodeCaller
}
func New() *LoggerOptions {
return &LoggerOptions{
DefaultParameters: nil,
Development: false,
Encoding: defaultEncoding,
OutputPaths: defaultOutputPaths,
ErrorOutputPaths: defaultErrorOutputPaths,
Level: defaultLoggingLevel,
TimeKey: defaultTimeKey,
LevelKey: defaultLevelKey,
NameKey: defaultNameKey,
CallerKey: defaultCallerKey,
StackTraceKey: defaultStackTraceKey,
MessageKey: defaultMessageKey,
EncodeLevel: &defaultEncodeLevel,
EncodeTime: &defaultEncodeTime,
EncodeDuration: &defaultEncodeDuration,
EncodeCaller: &defaultEncodeCaller,
}
}
func (c *LoggerOptions) UseDefaultEncodingIfNotSpecified() *LoggerOptions {
if len(c.Encoding) == 0 {
c.Encoding = defaultEncoding
}
return c
}
func (c *LoggerOptions) UseDefaultOutputPathsIfNotSpecified() *LoggerOptions {
if c.OutputPaths == nil || len(c.OutputPaths) == 0 {
c.OutputPaths = defaultOutputPaths
}
return c
}
func (c *LoggerOptions) UseDefaultErrorOutputPathsIfNotSpecified() *LoggerOptions {
if c.ErrorOutputPaths == nil || len(c.ErrorOutputPaths) == 0 {
c.ErrorOutputPaths = defaultErrorOutputPaths
}
return c
}
func (c *LoggerOptions) UseDefaultLoggingLevelIfNotSpecified() *LoggerOptions {
if len(c.Level) == 0 {
c.Level = defaultLoggingLevel
}
return c
}
func (c *LoggerOptions) UseDefaultTimeKeyIfNotSpecified() *LoggerOptions {
if len(c.TimeKey) == 0 {
c.TimeKey = defaultTimeKey
}
return c
}
func (c *LoggerOptions) UseDefaultLevelKeyIfNotSpecified() *LoggerOptions {
if len(c.LevelKey) == 0 {
c.LevelKey = defaultLevelKey
}
return c
}
func (c *LoggerOptions) UseDefaultNameKeyIfNotSpecified() *LoggerOptions {
if len(c.NameKey) == 0 {
c.NameKey = defaultNameKey
}
return c
}
func (c *LoggerOptions) UseDefaultCallerKeyIfNotSpecified() *LoggerOptions {
if len(c.CallerKey) == 0 {
c.CallerKey = defaultCallerKey
}
return c
}
func (c *LoggerOptions) UseDefaultMessageKeyIfNotSpecified() *LoggerOptions {
if len(c.MessageKey) == 0 {
c.MessageKey = defaultMessageKey
}
return c
}
func (c *LoggerOptions) UseDefaultFunctionKeyIfNotSpecified() *LoggerOptions {
if len(c.FunctionKey) == 0 {
c.FunctionKey = defaultFunctionKey
}
return c
}
func (c *LoggerOptions) UseDefaultStackTraceKeyIfNotSpecified() *LoggerOptions {
if len(c.StackTraceKey) == 0 {
c.StackTraceKey = defaultStackTraceKey
}
return c
}
func (c *LoggerOptions) UseDefaultEncodeLevelIfNotSpecified() *LoggerOptions {
if c.EncodeLevel == nil {
c.EncodeLevel = &defaultEncodeLevel
}
return c
}
func (c *LoggerOptions) UseDefaultEncodeTimeIfNotSpecified() *LoggerOptions {
if c.EncodeTime == nil {
c.EncodeTime = &defaultEncodeTime
}
return c
}
func (c *LoggerOptions) UseDefaultEncodeDurationIfNotSpecified() *LoggerOptions {
if c.EncodeDuration == nil {
c.EncodeDuration = &defaultEncodeDuration
}
return c
}
func (c *LoggerOptions) UseDefaultEncodeCallerIfNotSpecified() *LoggerOptions {
if c.EncodeCaller == nil {
c.EncodeCaller = &defaultEncodeCaller
}
return c
}