https://github.com/timestee/go-accesslog
A simple HTTP access log for golang.
https://github.com/timestee/go-accesslog
access-logs golang http http-server logger middleware
Last synced: 10 days ago
JSON representation
A simple HTTP access log for golang.
- Host: GitHub
- URL: https://github.com/timestee/go-accesslog
- Owner: timestee
- Created: 2019-05-12T13:23:21.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-15T09:16:06.000Z (almost 6 years ago)
- Last Synced: 2024-06-20T11:06:11.255Z (over 1 year ago)
- Topics: access-logs, golang, http, http-server, logger, middleware
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go-accesslog
[](https://travis-ci.org/timestee/go-accesslog) [](https://gowalker.org/github.com/timestee/go-accesslog) [](https://godoc.org/github.com/timestee/go-accesslog)[](https://sourcegraph.com/github.com/timestee/go-accesslog?badge)
A simple HTTP access logger for golang.
Usage:
```golang
func AccessLog(cb func(call *accesslog.Call)) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
// before request,install ResponseWriter proxy
call := &accesslog.Call{}
rwProxy := accesslog.NewResponseRecorder(rw, true)
accesslog.Before(call, r)
next.ServeHTTP(rwProxy, r)
// after request and callback
accesslog.After(call, rwProxy, r)
cb(call)
})
}
}
```