s3manager-web/logger.go

28 lines
392 B
Go
Raw Normal View History

2016-12-20 19:47:36 +01:00
package main
import (
"log"
"net/http"
"time"
)
// Logger logs HTTP requests
2017-03-05 15:02:59 +01:00
func Logger() Middleware {
return func(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
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-05 15:02:59 +01:00
next(w, r)
}
}
2016-12-20 19:47:36 +01:00
}