Categorygithub.com/pytimer/mux-logrus
modulepackage
0.0.0-20200505085744-ce5a5e748151
Repository: https://github.com/pytimer/mux-logrus.git
Documentation: pkg.go.dev

# README

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"

# Packages

No description provided by the author

# Functions

NewLogger returns a new *LoggingMiddleware, yay!.

# Structs

LoggingMiddleware is a middleware handler that logs the request as it goes in and the response as it goes out.
LogOptions logging middleware options.