Added access log to server and modified mock-fts to use it
This commit is contained in:
1 parent
2490519c2b
commit
02e3d910a2
10 files changed
+389
-29
No files matched your search
@@ -120,9 +120,11 @@ func isRequestIDChar(char byte) bool {
|
||||
return char == '-' || char == '_' || char == '.'
|
||||
}
|
||||
|
||||
// Logger logs one line per request. The query string is deliberately not
|
||||
// logged, as it may carry secrets. It logs to slog.Default() unless given
|
||||
// WithLogger.
|
||||
// Logger logs one line per request: at debug level, or at info level for a
|
||||
// connection hijack (a WebSocket upgrade), as one is logged per connection
|
||||
// rather than per request; a 4xx response is logged at warn level and a 5xx
|
||||
// at error level. The query string is deliberately not logged, as it may
|
||||
// carry secrets. It logs to slog.Default() unless given WithLogger.
|
||||
func Logger(opts ...Option) func(http.Handler) http.Handler {
|
||||
settings := applyOptions(opts)
|
||||
return func(next http.Handler) http.Handler {
|
||||
@@ -138,12 +140,14 @@ func Logger(opts ...Option) func(http.Handler) http.Handler {
|
||||
status = http.StatusOK
|
||||
}
|
||||
|
||||
level := slog.LevelInfo
|
||||
level := slog.LevelDebug
|
||||
switch {
|
||||
case status >= 500:
|
||||
level = slog.LevelError
|
||||
case status >= 400:
|
||||
level = slog.LevelWarn
|
||||
case recorder.hijacked:
|
||||
level = slog.LevelInfo
|
||||
}
|
||||
|
||||
settings.logger("http").LogAttrs(
|
||||
|
||||
Reference in new issue
Block a user