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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user