Skip to content

pytimer/mux-logrus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mux-logrus

GoDoc

logrus middleware for gorilla/mux

Getting Started

package main

import (
	"log"
	"net/http"

	"github.com/gorilla/mux"
	"github.com/pytimer/mux-logrus"
)

func index(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("hello!"))
}

func main() {
	r := mux.NewRouter()
	r.HandleFunc("/hello", index).Methods(http.MethodGet)

        // add logger middleware
	r.Use(muxlogrus.NewLogger().Middleware)

	address := ":8990"
	log.Printf("Listen on address %s", address)
	http.ListenAndServe(address, r)
}

output log:

time="2018-04-10T11:10:39+08:00" level=info msg="completed handling request" remoteAddr=127.0.0.1 status=400 took="6.838µs"

About

logrus middleware for groilla/mux

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages