2016-12-20 19:47:36 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Logger logs HTTP requests
|
2017-03-10 11:12:20 +01:00
|
|
|
func Logger() Adapter {
|
|
|
|
return func(next http.Handler) http.Handler {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2017-03-05 15:02:59 +01:00
|
|
|
start := time.Now()
|
2016-12-20 19:47:36 +01:00
|
|
|
|
2017-03-05 15:02:59 +01:00
|
|
|
defer func() {
|
|
|
|
log.Printf(
|
|
|
|
"%s\t%s\t%s",
|
|
|
|
r.Method,
|
|
|
|
r.RequestURI,
|
|
|
|
time.Since(start),
|
|
|
|
)
|
|
|
|
}()
|
2016-12-20 19:47:36 +01:00
|
|
|
|
2017-03-10 11:12:20 +01:00
|
|
|
next.ServeHTTP(w, r)
|
|
|
|
})
|
2017-03-05 15:02:59 +01:00
|
|
|
}
|
2016-12-20 19:47:36 +01:00
|
|
|
}
|