package middlewares import ( "net/http" "github.com/rs/zerolog/log" ) const CONTEXT_KEY_LOGRUS = ContextKey("logrus") // Inject a logrus entry into the context that has the url path already set func InjectLogrusMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { newContext := log.With().Str("url-path", r.URL.RawPath).Logger().WithContext(r.Context()) next.ServeHTTP(w, r.WithContext(newContext)) }) }