File tree Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,6 @@ func Logger(log slog.Logger) func(next http.Handler) http.Handler {
36
36
)
37
37
38
38
logContext := & RequestLoggerContext {
39
- Fields : map [string ]any {},
40
39
log : & httplog ,
41
40
written : false ,
42
41
}
@@ -87,21 +86,20 @@ func Logger(log slog.Logger) func(next http.Handler) http.Handler {
87
86
}
88
87
89
88
type RequestLoggerContext struct {
90
- Fields map [string ]any
91
-
92
89
log * slog.Logger
93
90
written bool
94
91
}
95
92
93
+ func (c * RequestLoggerContext ) WithFields (fields ... slog.Field ) {
94
+ newLogger := c .log .With (fields ... )
95
+ c .log = & newLogger
96
+ }
97
+
96
98
func (c * RequestLoggerContext ) WriteLog (ctx context.Context , msg string , status int ) {
97
99
if c .written {
98
100
return
99
101
}
100
102
c .written = true
101
- // append extra fields to the logger
102
- for k , v := range c .Fields {
103
- c .log .With (slog .F (k , v ))
104
- }
105
103
106
104
if status >= http .StatusInternalServerError {
107
105
c .log .Error (ctx , msg )
You can’t perform that action at this time.
0 commit comments