ginlogrus

package module
v0.0.0-...-3ab5813 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2017 License: MIT Imports: 10 Imported by: 1

README

gin-logrus

Logrus logger middleware for Gin

golang gin middleware logrus logger

Usage

import (
  "github.com/Sirupsen/logrus"
  "github.com/toorop/gin-logrus"
  "github.com/gin-gonic/gin"

log := logrus.New()
// hooks, config,...

r := gin.New()
r.Use(ginlogrus.Logger(log), gin.Recovery())

// pingpong
r.GET("/ping", func(c *gin.Context) {
	c.Data(200, "text/plain", []byte("pong"))
})

r.Run("127.0.0.1:8080")

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LogRequest = true

LogRequest activate the request body logging

View Source
var LogResponse = true

LogResponse activate the response body logging

View Source
var RespBodyExludedRoutes = []string{"css", "font", "js", "assets", "icons", "img", "images", "script", "favicon.ico", "swagger"}

RespBodyExludedRoutes are the routes for which we don't want to log the response body

View Source
var TimeFormat = "2006-01-02T15:04:05-0700"

TimeFormat is the logs desired time format

Functions

func ExcludeRespBodyLog

func ExcludeRespBodyLog(path string) bool

ExcludeRespBodyLog excludes some standard paths response body from being logged

func Logger

func Logger(log *logrus.Logger) gin.HandlerFunc

Logger is the logrus logger handler

func Tee

func Tee(httpReqBody *io.ReadCloser) []byte

Tee provides a copy of the request body to be logged

Types

type RespBodyLogger

type RespBodyLogger struct {
	gin.ResponseWriter
	// contains filtered or unexported fields
}

RespBodyLogger contains the body of the response for logging purpose

func (RespBodyLogger) Write

func (w RespBodyLogger) Write(b []byte) (int, error)

Write provides a copy of the response body to the logger

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL