-
Notifications
You must be signed in to change notification settings - Fork 0
/
requestLoggerConfiguration.go
71 lines (60 loc) · 2.52 KB
/
requestLoggerConfiguration.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
package logger
// RequestLoggerConfiguration represents options for logging HTTP request details.
type RequestLoggerConfiguration struct {
messageLoggerConfiguration
// Indicates whether the request query parameters should be included in the logged URL.
includeQueryInPath bool
}
// RequestLoggerOptions represents a function type that can be used to apply configuration to the RequestLoggerOptions struct.
type RequestLoggerOptions func(*RequestLoggerConfiguration)
// Default logger configuration
func defaultRequestLoggerConfiguration() RequestLoggerConfiguration {
return RequestLoggerConfiguration{
includeQueryInPath: false,
messageLoggerConfiguration: defaultMessageLoggerConfiguration(),
}
}
// NewHttpRequestLoggerConfiguration creates default RequestLoggerConfiguration with the provided options.
func NewHttpRequestLoggerConfiguration(options ...RequestLoggerOptions) RequestLoggerConfiguration {
config := defaultRequestLoggerConfiguration()
for _, option := range options {
option(&config)
}
return config
}
// WithIncludeQueryInPath is an option that enable include Query InPath in the LoggingOptions.
func WithIncludeQueryInPath(includeQueryInPath bool) RequestLoggerOptions {
return func(l *RequestLoggerConfiguration) {
l.includeQueryInPath = includeQueryInPath
}
}
// WithRequestBody is an option that sets that enable to log body in the LoggingOptions.
func WithRequestBody(logBody bool) RequestLoggerOptions {
return func(l *RequestLoggerConfiguration) {
l.body = logBody
}
}
// WithRequestHeaders is an option that sets that enable to log headers in the LoggingOptions.
func WithRequestHeaders(logHeaders bool) RequestLoggerOptions {
return func(l *RequestLoggerConfiguration) {
l.headers = logHeaders
}
}
// WithExcludeRequestHeaders is an option that sets the Headers To Exclude in the LoggingOptions.
func WithExcludeRequestHeaders(excludeHeaders ...string) RequestLoggerOptions {
return func(l *RequestLoggerConfiguration) {
l.excludeHeaders = excludeHeaders
}
}
// WithIncludeRequestHeaders is an option that sets the Headers To Include in the LoggingOptions.
func WithIncludeRequestHeaders(includeHeaders ...string) RequestLoggerOptions {
return func(l *RequestLoggerConfiguration) {
l.includeHeaders = includeHeaders
}
}
// WithWhitelistRequestHeaders is an option that sets the Headers To Whitelist in the LoggingOptions.
func WithWhitelistRequestHeaders(whitelistHeaders ...string) RequestLoggerOptions {
return func(l *RequestLoggerConfiguration) {
l.whitelistHeaders = whitelistHeaders
}
}