https://github.com/crhntr/httplog
A simple http request logger
https://github.com/crhntr/httplog
Last synced: 3 months ago
JSON representation
A simple http request logger
- Host: GitHub
- URL: https://github.com/crhntr/httplog
- Owner: crhntr
- License: other
- Created: 2018-01-13T22:56:08.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2025-04-01T19:24:54.000Z (4 months ago)
- Last Synced: 2025-04-04T20:11:53.570Z (3 months ago)
- Language: Go
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# httplog
**This was initially pulled out of a side project then we used the repo as an acceptance test stub at Pivotal/VMware (note the silly commits)**
`httplog` is a http request logger to wrap your http.Handler.
[](https://godoc.org/github.com/crhntr/httplog)
## Example
```go
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}
```