https://github.com/gowww/log
⏱ A handler that logs each request/response
https://github.com/gowww/log
go golang handler http log logging middleware request
Last synced: about 1 month ago
JSON representation
⏱ A handler that logs each request/response
- Host: GitHub
- URL: https://github.com/gowww/log
- Owner: gowww
- License: mit
- Created: 2016-05-16T23:58:43.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2020-09-11T17:33:39.000Z (over 5 years ago)
- Last Synced: 2025-08-13T23:35:58.836Z (8 months ago)
- Topics: go, golang, handler, http, log, logging, middleware, request
- Language: Go
- Homepage:
- Size: 26.4 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [](https://github.com/gowww) log [](https://godoc.org/github.com/gowww/log) [](https://travis-ci.org/gowww/log) [](https://coveralls.io/github/gowww/log?branch=master) [](https://goreportcard.com/report/github.com/gowww/log) 
Package [log](https://godoc.org/github.com/gowww/log) provides a handler that logs each request/response (time, duration, status, method, path).
The log formatting can either be couloured or not.
## Installing
1. Get package:
```Shell
go get -u github.com/gowww/log
```
2. Import it in your code:
```Go
import "github.com/gowww/log"
```
## Usage
To wrap an [http.Handler](https://golang.org/pkg/net/http/#Handler), use [Handle](https://godoc.org/github.com/gowww/log#Handle):
```Go
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello")
})
http.ListenAndServe(":8080", log.Handle(mux, nil))
```
To wrap an [http.HandlerFunc](https://golang.org/pkg/net/http/#HandlerFunc), use [HandleFunc](https://godoc.org/github.com/gowww/log#HandleFunc):
```Go
http.Handle("/", log.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello")
}, nil))
http.ListenAndServe(":8080", nil)
```
All in all, make sure to include this handler above any other handler to get accurate performance logs.
### Colorized output
If you are on a Unix-based OS, you can get a colorized output:
```Go
log.Handle(handler, &log.Options{
Color: true,
})
```
## Output
### Colorized
