hooker/logging.go

29 lines
480 B
Go
Raw Normal View History

2023-09-19 22:47:19 +02:00
package main
import (
"fmt"
"log"
"net/http"
"time"
)
type LoggingHTTPHandler struct {
Handler http.Handler
}
func (l *LoggingHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
t1 := time.Now().UTC()
l.Handler.ServeHTTP(w, r)
log.Println(
fmt.Sprintf("%s %s %s %v", r.RemoteAddr, r.Method, r.URL.Path, time.Since(t1)),
)
}
func NewLogger(handler http.Handler) LoggingHTTPHandler {
return LoggingHTTPHandler{handler}
}