feat: adds configurable HTTP request path exclusion from logging

This commit is contained in:
2025-08-26 14:51:39 -04:00
parent 2310ac574c
commit 063ff0f1d0
3 changed files with 43 additions and 10 deletions

View File

@@ -10,6 +10,8 @@ import (
"time"
"github.com/rs/zerolog"
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
)
var ExcludeFromLogging = regexp.MustCompile(`\/(ready|live|metrics)$`)
@@ -21,12 +23,22 @@ type LoggingResponseWriter struct {
}
func loggingMiddleware(appCtx context.Context, next http.Handler) http.Handler {
appConfig := config.MustFromCtx(appCtx)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if ExcludeFromLogging.Match([]byte(r.URL.Path)) {
next.ServeHTTP(w, r)
return
}
// User-configurable logging exclusions
for _, re := range appConfig.HTTP.GetExcludeRegexps() {
if re.MatchString(r.URL.Path) {
next.ServeHTTP(w, r)
return
}
}
log := zerolog.Ctx(appCtx)
start := time.Now()