logger

package module
v0.0.0-...-6711eff Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2020 License: MIT Imports: 13 Imported by: 0

README

logger

Gin middleware/handler to logger url path using rs/zerolog.

Example:

package main

import (
	"github.com/chandraanwar91/logger"
	"github.com/gin-gonic/gin"
)

func main() {
	//setting confing
	config := logger.Config{
		SkipPath:               []string{"/application/health"}, // if we want to skip log
		SkipLoggedPathResponse: []string{"/application/get-credential"}, //if we don't want to log body response
	}

	r := gin.New()

	// Add a logger middleware, which:
	//   - Logs all requests, like a combined access and error log.
	//   - Logs to stdout.
	r.Use(logger.SetLogger(config))

	// Listen and Server in 0.0.0.0:8080
	r.Run(":8080")
}

Documentation

Index

Constants

View Source
const (
	HeaderXRequestID = "X-Request-ID"
)

Headers

Variables

View Source
var (
	// DefaultLoggerConfig is the default Logger middleware config.
	DefaultLoggerConfig = Config{
		UTC: true,
		Format: `{"time":"${time_rfc3339_nano}","id":"${id}","remote_ip":"${remote_ip}",` +
			`"host":"${host}","method":"${method}","uri":"${uri}","user_agent":"${user_agent}",` +
			`"status":${status},"error":"${error}","latency":${latency},"latency_human":"${latency_human}"` +
			`,"bytes_in":${bytes_in},"bytes_out":${bytes_out}}` + "\n",
		Output: os.Stdout,
	}
)

Functions

func CxtRequestID

func CxtRequestID(c *gin.Context) string

func GetAllHeaders

func GetAllHeaders(c *gin.Context) string

func SetLogger

func SetLogger(config ...Config) gin.HandlerFunc

SetLogger initializes the logging middleware.

Types

type Config

type Config struct {
	Logger *zerolog.Logger
	// UTC a boolean stating whether to use UTC time zone or local.
	UTC                    bool
	SkipPath               []string
	SkipPathRegexp         *regexp.Regexp
	Format                 string
	Output                 io.Writer
	SkipLoggedPathResponse []string
}

Config defines the config for logger middleware

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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