30 lines
721 B
Go
30 lines
721 B
Go
|
package middleware
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"time"
|
||
|
|
||
|
"git.staur.ca/stobbsm/clustvirt/lib/log"
|
||
|
)
|
||
|
|
||
|
// Logger uses the in package log module to handle route logging
|
||
|
func Logger(next http.Handler) http.Handler {
|
||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||
|
start := time.Now()
|
||
|
defer func() {
|
||
|
log.Info("router.middleware.Logger").
|
||
|
Str("httpMethod", r.Method).
|
||
|
Str("host", r.Host).
|
||
|
Str("uri", r.URL.RequestURI()).
|
||
|
Str("user_agent", r.UserAgent()).
|
||
|
Str("referer", r.Referer()).
|
||
|
Strs("transfer-encoding", r.TransferEncoding).
|
||
|
Int64("length", r.ContentLength).
|
||
|
Dur("elasped_ms", time.Since(start)).
|
||
|
Msg("incoming connection")
|
||
|
}()
|
||
|
|
||
|
next.ServeHTTP(w, r)
|
||
|
})
|
||
|
}
|