log.go 322 B

12345678910111213141516171819202122
  1. package kyra
  2. import "log"
  3. import "net/http"
  4. type LoggerMiddle struct {
  5. Logger *log.Logger
  6. After http.Handler
  7. }
  8. func (l *LoggerMiddle) ServeHTTP(
  9. w http.ResponseWriter, r *http.Request,
  10. ) {
  11. if l.Logger != nil {
  12. l.Logger.Printf(
  13. "%s %s %q\n",
  14. r.RemoteAddr, r.Method, r.URL,
  15. )
  16. }
  17. l.After.ServeHTTP(w, r)
  18. }