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

Function MethodHandler

hlog/hlog.go:52–62  ·  view source on GitHub ↗

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

(fieldKey string)

Source from the content-addressed store, hash-verified

50// MethodHandler adds the request method as a field to the context's logger
51// using fieldKey as field key.
52func MethodHandler(fieldKey string) func(next http.Handler) http.Handler {
53 return func(next http.Handler) http.Handler {
54 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
55 log := zerolog.Ctx(r.Context())
56 log.UpdateContext(func(c zerolog.Context) zerolog.Context {
57 return c.Str(fieldKey, r.Method)
58 })
59 next.ServeHTTP(w, r)
60 })
61 }
62}
63
64// RequestHandler adds the request method and URL as a field to the context's logger
65// using fieldKey as field key.

Callers 3

TestMethodHandlerFunction · 0.85
TestCombinedHandlersFunction · 0.85
BenchmarkHandlersFunction · 0.85

Calls 3

CtxFunction · 0.92
UpdateContextMethod · 0.80
StrMethod · 0.45

Tested by 3

TestMethodHandlerFunction · 0.68
TestCombinedHandlersFunction · 0.68
BenchmarkHandlersFunction · 0.68