MCPcopy
hub / github.com/rs/zerolog / RequestHandler

Function RequestHandler

hlog/hlog.go:66–76  ·  view source on GitHub ↗

RequestHandler adds the request method and URL as a field to the context's logger using fieldKey as field key.

(fieldKey string)

Source from the content-addressed store, hash-verified

64// RequestHandler adds the request method and URL as a field to the context's logger
65// using fieldKey as field key.
66func RequestHandler(fieldKey string) func(next http.Handler) http.Handler {
67 return func(next http.Handler) http.Handler {
68 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
69 log := zerolog.Ctx(r.Context())
70 log.UpdateContext(func(c zerolog.Context) zerolog.Context {
71 return c.Str(fieldKey, r.Method+" "+r.URL.String())
72 })
73 next.ServeHTTP(w, r)
74 })
75 }
76}
77
78// RemoteAddrHandler adds the request's remote address as a field to the context's logger
79// using fieldKey as field key.

Callers 3

TestRequestHandlerFunction · 0.85
TestCombinedHandlersFunction · 0.85
BenchmarkHandlersFunction · 0.85

Calls 4

CtxFunction · 0.92
UpdateContextMethod · 0.80
StrMethod · 0.45
StringMethod · 0.45

Tested by 3

TestRequestHandlerFunction · 0.68
TestCombinedHandlersFunction · 0.68
BenchmarkHandlersFunction · 0.68