MethodHandler adds the request method as a field to the context's logger using fieldKey as field key.
(fieldKey string)
| 50 | // MethodHandler adds the request method as a field to the context's logger |
| 51 | // using fieldKey as field key. |
| 52 | func 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. |