29 lines
480 B
Go
29 lines
480 B
Go
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}
|
|
}
|