Skip to content

Commit 6120f27

Browse files
committed
feat: added options for customizing sanitizers for logging middleware
1 parent 2ba4291 commit 6120f27

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

logger/option.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package logger
22

33
import (
44
"context"
5+
"log/slog"
56
"net/http"
67
"net/url"
78

89
"github.com/cappuccinotm/slogx"
9-
"log/slog"
1010
)
1111

1212
// Option is a function that configures a Logger.
@@ -36,6 +36,21 @@ func WithLogFn(fn func(context.Context, *LogParts)) Option {
3636
return func(l *Logger) { l.logFn = fn }
3737
}
3838

39+
// WithSanitizeHeaders sets a custom function to sanitize headers.
40+
func WithSanitizeHeaders(fn func(http.Header) map[string]string) Option {
41+
return func(l *Logger) { l.sanitizeHeadersFn = fn }
42+
}
43+
44+
// WithSanitizeQuery sets a custom function to sanitize query parameters.
45+
func WithSanitizeQuery(fn func(string) string) Option {
46+
return func(l *Logger) { l.sanitizeQueryFn = fn }
47+
}
48+
49+
// WithMaskIP sets a custom function to mask IP addresses.
50+
func WithMaskIP(fn func(string) string) Option {
51+
return func(l *Logger) { l.maskIPFn = fn }
52+
}
53+
3954
// Log2Slog is the default log function that logs to slog.
4055
func Log2Slog(ctx context.Context, parts *LogParts, logger *slog.Logger) {
4156
msg := "http server request"

0 commit comments

Comments
 (0)