Last active
May 29, 2017 22:16
-
-
Save Adron/481f0df5af0403720adb3da6e6782cf5 to your computer and use it in GitHub Desktop.
A basic logger for getting started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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