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

Function URLHandler

hlog/hlog.go:38–48  ·  view source on GitHub ↗

URLHandler adds the requested URL as a field to the context's logger using fieldKey as field key.

(fieldKey string)

Source from the content-addressed store, hash-verified

36// URLHandler adds the requested URL as a field to the context's logger
37// using fieldKey as field key.
38func URLHandler(fieldKey string) func(next http.Handler) http.Handler {
39 return func(next http.Handler) http.Handler {
40 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
41 log := zerolog.Ctx(r.Context())
42 log.UpdateContext(func(c zerolog.Context) zerolog.Context {
43 return c.Str(fieldKey, r.URL.String())
44 })
45 next.ServeHTTP(w, r)
46 })
47 }
48}
49
50// MethodHandler adds the request method as a field to the context's logger
51// using fieldKey as field key.

Callers 3

TestURLHandlerFunction · 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

TestURLHandlerFunction · 0.68
TestCombinedHandlersFunction · 0.68
BenchmarkHandlersFunction · 0.68