Skip to content

Instantly share code, notes, and snippets.

@webdev
Created January 20, 2015 23:40
Show Gist options
  • Select an option

  • Save webdev/5f0ddd0d29ea1eca806a to your computer and use it in GitHub Desktop.

Select an option

Save webdev/5f0ddd0d29ea1eca806a to your computer and use it in GitHub Desktop.
type loggingResponseWriter interface {¬
+ ▸ http.ResponseWriter¬
+ ▸ Status() int¬
+ ▸ Size() int¬
+ }¬
+ ¬
func Log(handler http.Handler) http.Handler {¬
▸ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {¬
~ ¬
~ ▸ ▸ logger := &loggingResponseWriter{w: w}¬
+ ¬
+ ▸ ▸ handler.ServeHTTP(logger, r)¬
+ ¬
+ ▸ ▸ log.Printf("%s %s %s %s\n", r.RemoteAddr, r.Method, r.URL, logger.Status())¬
▸ })¬
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment