URLHandler adds the requested URL as a field to the context's logger using fieldKey as field key.
(fieldKey string)
| 36 | // URLHandler adds the requested URL as a field to the context's logger |
| 37 | // using fieldKey as field key. |
| 38 | func 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. |