Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/logPublic

⏱ A handler that logs each request/response

License

NotificationsYou must be signed in to change notification settings

gowww/log

Repository files navigation

gowww logGoDocBuildCoverageGo ReportStatus Stable

Packagelog 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 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.

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

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp