feat(14.2-01): opt-in http.access_log request log in surf

- one Info record "http request" per request with method, matched route
  pattern, status and duration_ms; path without the query only when no
  route matched
- the matched route records its pattern through a request-scoped entry,
  so locale prefix rewrites do not hide it
- logs through the published *slog.Logger or slog.Default; off by default
- surf README, logging and configuration docs describe the key
This commit is contained in:
2026-10-11 17:42:51 +02:00
parent ad1fa5abfa
commit 2d68eab3c0
6 changed files with 269 additions and 1 deletions

View File

@@ -378,7 +378,11 @@ func (r *Router) compile() (http.Handler, error) {
if err := registerOverlapFamilies(mux, r.routes, handlers, families); err != nil {
return nil, err
}
return r.stripLocalePrefix(pathScopedCORS(r.corsCfg, mux)), nil
h := r.stripLocalePrefix(pathScopedCORS(r.corsCfg, mux))
if accessLogEnabled(r.app) {
h = accessLog(r.app, h)
}
return h, nil
}
// handleRoute registers a route, converting a ServeMux conflict panic into an error.
@@ -445,6 +449,8 @@ func (r *Router) wrap(rt route) (http.Handler, error) {
} else {
h = recoverJSON(h)
}
// Outermost: name the matched route for the access log (accesslog.go).
h = recordPattern(rt.method+" "+rt.path, h)
return h, nil
}