mirror of
https://github.com/ordinary-dev/phoenix
synced 2024-09-20 03:40:29 +05:00
23 lines
402 B
Go
23 lines
402 B
Go
|
package middleware
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"time"
|
||
|
|
||
|
log "github.com/sirupsen/logrus"
|
||
|
)
|
||
|
|
||
|
func LoggingMiddleware(next http.Handler) http.Handler {
|
||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||
|
start := time.Now()
|
||
|
|
||
|
next.ServeHTTP(w, r)
|
||
|
|
||
|
log.WithFields(log.Fields{
|
||
|
"latency": time.Since(start),
|
||
|
"method": r.Method,
|
||
|
"path": r.URL.Path,
|
||
|
}).Info("Request")
|
||
|
})
|
||
|
}
|