Skip to content

Latest commit

 

History

History
19 lines (17 loc) · 630 Bytes

README.md

File metadata and controls

19 lines (17 loc) · 630 Bytes

httplog

httplog is a http request logger to wrap your http.Handler.

GoDoc

Example

mux := http.NewServeMux()
mux.HandleFunc("/greeting", func(w http.ResponseWriter, r *http.Request) {
  w.WriteHeader(http.StatusOK)
  fmt.Fprint(w, "Hello, world!")
})
logMux := httplog.Wrap(mux)
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/greeting", nil)
logMux.ServeHTTP(w, r)
// Output:
// {"type": "HTTP_REQUEST", "method": "GET", "path": "/greeting", "duration": "48.572µs", "status": 200}