-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Dynom/AddingRequestLogger
Adding a request-logger, mostly to debug stuff in the k8s cluster
- Loading branch information
Showing
2 changed files
with
24 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"time" | ||
|
||
"github.com/go-kit/kit/log" | ||
) | ||
|
||
// NewRequestLogger logs each request with start and ending times | ||
func NewRequestLogger(l log.Logger) func(h http.Handler) http.Handler { | ||
return func(h http.Handler) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
start := time.Now() | ||
l.Log("request", "start", "path", r.URL.Path, "remote_addr", r.RemoteAddr) | ||
defer l.Log("request", "end", "duration", time.Since(start)) | ||
|
||
h.ServeHTTP(w, r) | ||
}) | ||
} | ||
} |
This file contains 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