Skip to content
/ log Public

⏱ A handler that logs each request/response

License

Notifications You must be signed in to change notification settings

gowww/log

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gowww log GoDoc Build Coverage Go Report Status Stable

Package 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:

    go get -u github.com/gowww/log
  2. Import it in your code:

    import "github.com/gowww/log"

Usage

To wrap an http.Handler, use Handle:

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, use HandleFunc:

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:

log.Handle(handler, &log.Options{
	Color: true,
})

Output

Colorized

gowww-log-color

About

⏱ A handler that logs each request/response

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages