func RequestLogger()

in api/pkg/middleware/request_logger.go [25:45]


func RequestLogger() func(next http.Handler) http.Handler {
	return func(next http.Handler) http.Handler {
		fn := func(w http.ResponseWriter, r *http.Request) {
			ctx := r.Context()

			d := zerolog.Dict().
				Str("method", r.Method).
				Str("path", r.URL.Path).
				Str("uri", r.URL.String()).
				Str("host", r.Host).
				Str("remote", r.RemoteAddr)

			logger := log.Logger.With().Dict("request", d).Logger()

			next.ServeHTTP(w, r.WithContext(logger.WithContext(ctx)))

		}

		return http.HandlerFunc(fn)
	}
}