Skip to content

Instantly share code, notes, and snippets.

@Adron
Last active May 29, 2017 22:16
Show Gist options
  • Select an option

  • Save Adron/481f0df5af0403720adb3da6e6782cf5 to your computer and use it in GitHub Desktop.

Select an option

Save Adron/481f0df5af0403720adb3da6e6782cf5 to your computer and use it in GitHub Desktop.
A basic logger for getting started.
package main
import (
"log"
"net/http"
"time"
)
func Logger(inner http.Handler, name string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
inner.ServeHTTP(w, r)
log.Printf(
"%s\t%s\t%s\t%s",
r.Method,
r.RequestURI,
name,
time.Since(start),
)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment