-
Notifications
You must be signed in to change notification settings - Fork 9
/
options.go
78 lines (66 loc) · 2.3 KB
/
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
package ginlogrus
import (
"io"
"os"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)
// Option - define options for WithTracing()
type Option func(*options)
// Function definition for reduced logging. The return value of this function
// will be used to determine whether or not a log will be output.
type ReducedLoggingFunc func(c *gin.Context) bool
type options struct {
aggregateLogging bool
logLevel logrus.Level
emptyAggregateEntries bool
reducedLoggingFunc ReducedLoggingFunc
writer io.Writer
banner string
}
// defaultOptions - some defs options to NewJWTCache()
var defaultOptions = options{
aggregateLogging: false,
logLevel: logrus.DebugLevel,
emptyAggregateEntries: true,
reducedLoggingFunc: func(c *gin.Context) bool { return true },
writer: os.Stdout,
banner: DefaultBanner,
}
// WithAggregateLogging - define an Option func for passing in an optional aggregateLogging
func WithAggregateLogging(a bool) Option {
return func(o *options) {
o.aggregateLogging = a
}
}
// WithEmptyAggregateEntries - define an Option func for printing aggregate logs with empty entries
func WithEmptyAggregateEntries(a bool) Option {
return func(o *options) {
o.emptyAggregateEntries = a
}
}
// WithReducedLoggingFunc - define an Option func for reducing logs based on a custom function
func WithReducedLoggingFunc(a ReducedLoggingFunc) Option {
return func(o *options) {
o.reducedLoggingFunc = a
}
}
// WithLogLevel - define an Option func for passing in an optional logLevel
func WithLogLevel(logLevel logrus.Level) Option {
return func(o *options) {
o.logLevel = logLevel
}
}
// WithWriter allows users to define the writer used for middlware aggregagte logging, the default writer is os.Stdout
func WithWriter(w io.Writer) Option {
return func(o *options) {
o.writer = w
}
}
// WithLogCustomBanner allows users to define their own custom banner. There is some overlap with this name and the LogBufferOption.CustomBanner and yes,
// they are related options, but I didn't want to make a breaking API change to support this new option... so we'll have to live with a bit of confusion/overlap in option names
func WithLogCustomBanner(b string) Option {
return func(o *options) {
o.banner = b
}
}