mirror of
https://github.com/hanzo-fi/stack.git
synced 2026-10-30 20:34:43 +00:00
25 lines
567 B
Go
25 lines
567 B
Go
package middlewares
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/formancehq/stack/libs/go-libs/logging"
|
|
)
|
|
|
|
func Log() func(h http.Handler) http.Handler {
|
|
return func(h http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
start := time.Now()
|
|
h.ServeHTTP(w, r)
|
|
latency := time.Since(start)
|
|
logging.FromContext(r.Context()).WithFields(map[string]interface{}{
|
|
"method": r.Method,
|
|
"path": r.URL.Path,
|
|
"latency": latency,
|
|
"user_agent": r.UserAgent(),
|
|
}).Info("Request")
|
|
})
|
|
}
|
|
}
|