logging.go 457 B

1234567891011121314151617181920
  1. package middleware
  2. import (
  3. "log"
  4. "net/http"
  5. "time"
  6. )
  7. // LoggingMiddleware logs information about each HTTP request
  8. func LoggingMiddleware(next http.Handler) http.Handler {
  9. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  10. start := time.Now()
  11. log.Printf("Started %s %s from %s", r.Method, r.URL.Path, r.RemoteAddr)
  12. next.ServeHTTP(w, r)
  13. log.Printf("Completed %s %s in %v", r.Method, r.URL.Path, time.Since(start))
  14. })
  15. }