Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/crhntr/httplog
A simple http request logger
https://github.com/crhntr/httplog
Last synced: about 1 month 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 (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2020-10-20T18:54:50.000Z (about 4 years ago)
- Last Synced: 2023-08-09T15:30:41.936Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# httplog
`httplog` is a http request logger to wrap your http.Handler.[![GoDoc](https://godoc.org/github.com/crhntr/httplog?status.svg)](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}
```