From b0317f10514d04375c7e8c938d15d0f90aab547e Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Wed, 26 Jul 2023 13:50:55 +0200 Subject: [PATCH] Log the whole request path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Next handlers might cut up request’s URL.Path, so i need to keep a copy before calling next to log the whole thing. --- pkg/http/logger.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/http/logger.go b/pkg/http/logger.go index ab880fa..91d7f54 100644 --- a/pkg/http/logger.go +++ b/pkg/http/logger.go @@ -38,6 +38,7 @@ func LogRequest(next http.Handler) http.Handler { t := time.Now() logger := loggerResponseWriter{w, 0, 0} + requestPath := r.URL.Path next.ServeHTTP(&logger, r) statusCode := logger.statusCode @@ -47,7 +48,7 @@ func LogRequest(next http.Handler) http.Handler { log.Printf("HTTP - %s %s \"%s\" %d %d %s\n", RemoteAddr(r), r.Method, - r.URL.Path, + requestPath, statusCode, logger.responseSize, time.Since(t),