clustvirt/router/middleware/logger.go
Matthew Stobbs 4c132c4abf removed chi router
- switched to go 1.22 net/http ServeMux for routing
- seems to be working really well
2024-03-23 23:59:56 -06:00

31 lines
801 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 {
log.Info("logger.Logger").Str("middleware", "Logger").Msg("middleware loaded")
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)
})
}