File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -313,16 +313,18 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
313313 }
314314 }
315315
316- // encode the request for logging purposes before
316+ // clone the request for logging purposes before
317317 // it enters any handler chain; this is necessary
318318 // to capture the original request in case it gets
319319 // modified during handling
320+ // cloning the request and using .WithLazy is considerably faster
321+ // than using .With, which will JSON encode the request immediately
320322 shouldLogCredentials := s .Logs != nil && s .Logs .ShouldLogCredentials
321323 loggableReq := zap .Object ("request" , LoggableHTTPRequest {
322- Request : r ,
324+ Request : r . Clone ( r . Context ()) ,
323325 ShouldLogCredentials : shouldLogCredentials ,
324326 })
325- errLog := s .errorLogger .With (loggableReq )
327+ errLog := s .errorLogger .WithLazy (loggableReq )
326328
327329 var duration time.Duration
328330
You can’t perform that action at this time.
0 commit comments