logger.go 354 B

12345678910111213141516171819202122232425
  1. package main
  2. import (
  3. "log"
  4. "net/http"
  5. "time"
  6. )
  7. // Logger test
  8. func Logger(inner http.Handler, name string) http.Handler {
  9. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  10. start := time.Now()
  11. inner.ServeHTTP(w, r)
  12. log.Printf(
  13. "%s\t%s\t%s\t%s",
  14. r.Method,
  15. r.RequestURI,
  16. name,
  17. time.Since(start),
  18. )
  19. })
  20. }