Log the whole request path

Next handlers might cut up request’s URL.Path, so i need to keep a copy
before calling next to log the whole thing.
This commit is contained in:
jordi fita mas 2023-07-26 13:50:55 +02:00
parent ebe8217862
commit b0317f1051
1 changed files with 2 additions and 1 deletions

View File

@ -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),