2024-03-24 04:05:06 +00:00
|
|
|
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 {
|
2024-03-24 05:59:56 +00:00
|
|
|
log.Info("logger.Logger").Str("middleware", "Logger").Msg("middleware loaded")
|
2024-03-24 04:05:06 +00:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|