s3manager-web/logging.go

26 lines
433 B
Go
Raw Normal View History

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