项目作者: syhlion

项目描述 :
http handler middleware
高级语言: Go
项目地址: git://github.com/syhlion/httplog.git
创建时间: 2016-12-30T06:09:53Z
项目社区:https://github.com/syhlion/httplog

开源协议:MIT License

下载


httplog middleware

Go Report Card
Build Status

negroni middleware

Install

go get -u github.com/syhlion/httplog

Example

  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. "github.com/urfave/negroni"
  6. )
  7. func main() {
  8. mux := http.NewServeMux()
  9. mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
  10. fmt.Fprintf(w, "Welcome to the home page!")
  11. })
  12. n := negroni.New()
  13. n.Use(httplog.NewLogger())
  14. n.UseHandler(mux)
  15. http.ListenAndServe(":3004", n)
  16. }

Will print a log similar to:

  1. [http log] 127.0.0.1:46945 - [2015-12-30 09:05:27.502464588 +0800 CST] "POST /register" 200 37.96608ms "username=syhlion&email=xxx@gmail.com"
  2. [http log] 127.0.0.1:46947 - [2015-12-30 10:06:29.502464588 +0800 CST] "GET /feeds" 200 37.96608ms ""
  3. [http log] 127.0.0.1:46956 - [2015-12-31 12:15:33.502464588 +0800 CST] "GET /news" 200 37.96608ms "offset=0&limit=10"