-
Notifications
You must be signed in to change notification settings - Fork 9
/
logBufferOptions.go
54 lines (46 loc) · 1.52 KB
/
logBufferOptions.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
package ginlogrus
const DefaultBanner = "[GIN] --------------------------------------------------------------- GinLogrusWithTracing ----------------------------------------------------------------"
// LogBufferOption - define options for LogBuffer
type LogBufferOption func(*logBufferOptions)
type logBufferOptions struct {
addBanner bool
withHeaders map[string]interface{}
maxSize uint
banner string
}
// DefaultLogBufferMaxSize - avg single spaced page contains 3k chars, so 100k == 33 pages which is a reasonable max
const DefaultLogBufferMaxSize = 100000
func defaultLogBufferOptions() logBufferOptions {
return logBufferOptions{
maxSize: DefaultLogBufferMaxSize,
banner: DefaultBanner,
addBanner: false,
}
}
// WithBanner - define an Option func for passing in an optional add Banner
func WithBanner(a bool) LogBufferOption {
return func(o *logBufferOptions) {
o.addBanner = a
}
}
// WithHeader - define an Option func for passing in a set of optional header
func WithHeader(k string, v interface{}) LogBufferOption {
return func(o *logBufferOptions) {
if o.withHeaders == nil {
o.withHeaders = make(map[string]interface{})
}
o.withHeaders[k] = v
}
}
// WithMaxSize specifies the bounded max size the logBuffer can grow to
func WithMaxSize(s uint) LogBufferOption {
return func(o *logBufferOptions) {
o.maxSize = s
}
}
// WithCustomBanner allows users to define their own custom banner
func WithCustomBanner(b string) LogBufferOption {
return func(o *logBufferOptions) {
o.banner = b
}
}