s3manager-web/vendor/github.com/mastertinner/adapters/logging/logging.go
2017-05-08 23:29:47 +02:00

27 lines
483 B
Go

package logging
import (
"log"
"net/http"
"time"
"github.com/mastertinner/adapters"
)
// Handler logs HTTP requests.
func Handler(logger *log.Logger) adapters.Adapter {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func(start time.Time) {
logger.Printf(
"%s\t%s\t%s",
r.Method,
r.RequestURI,
time.Since(start),
)
}(time.Now())
next.ServeHTTP(w, r)
})
}
}