From 31dadf6c6a5da53f764ff829ee989a014b86f4b1 Mon Sep 17 00:00:00 2001 From: Guillaume Belanger Date: Fri, 14 Jun 2024 16:07:39 -0400 Subject: [PATCH] chore: do not log calls to /_next --- internal/api/middleware.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/api/middleware.go b/internal/api/middleware.go index 8e8e3d1..872edc4 100644 --- a/internal/api/middleware.go +++ b/internal/api/middleware.go @@ -3,6 +3,7 @@ package server import ( "log" "net/http" + "strings" "github.com/canonical/gocert/internal/metrics" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -71,10 +72,15 @@ func metricsMiddleware(ctx *middlewareContext) middleware { func loggingMiddleware(ctx *middlewareContext) middleware { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - clonedWwriter := newResponseWriter(w) + clonedWriter := newResponseWriter(w) next.ServeHTTP(w, r) - log.Println(r.Method, r.URL.Path, clonedWwriter.statusCode, http.StatusText(clonedWwriter.statusCode)) - ctx.responseStatusCode = clonedWwriter.statusCode + + // Suppress logging for static files + if !strings.HasPrefix(r.URL.Path, "/_next") { + log.Println(r.Method, r.URL.Path, clonedWriter.statusCode, http.StatusText(clonedWriter.statusCode)) + } + + ctx.responseStatusCode = clonedWriter.statusCode }) } }