Skip to content

Commit

Permalink
chore: do not log calls to /_next
Browse files Browse the repository at this point in the history
  • Loading branch information
gruyaume committed Jun 14, 2024
1 parent e6db72b commit 31dadf6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/api/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"log"
"net/http"
"strings"

"github.com/canonical/gocert/internal/metrics"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand Down Expand Up @@ -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
})
}
}

0 comments on commit 31dadf6

Please sign in to comment.