- Notifications
You must be signed in to change notification settings - Fork0
⏱ A handler that logs each request/response
License
NotificationsYou must be signed in to change notification settings
gowww/log
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Packagelog provides a handler that logs each request/response (time, duration, status, method, path).
The log formatting can either be couloured or not.
Get package:
go get -u github.com/gowww/log
Import it in your code:
import"github.com/gowww/log"
To wrap anhttp.Handler, useHandle:
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 anhttp.HandlerFunc, useHandleFunc:
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.
If you are on a Unix-based OS, you can get a colorized output:
log.Handle(handler,&log.Options{Color:true,})
About
⏱ A handler that logs each request/response
Topics
Resources
License
Stars
Watchers
Forks
Packages0
No packages published