blob: 065a6a72088aa02dc879d17a6fb3bdaa423a1fab (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package middleware
import (
"net/http"
"log/slog"
)
func Logger(logger *slog.Logger) Middleware {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
next.ServeHTTP(w, r)
requestID := GetRequestID(r)
args := []any{
slog.String("proto", r.Proto),
slog.String("method", r.Method),
slog.String("request_uri", r.RequestURI),
slog.String("request_id", requestID),
}
logger.InfoContext(
r.Context(),
"request",
args...,
)
})
}
}
|