gin_request_logger

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2022 License: MIT Imports: 8 Imported by: 0

README

gin-request-logger

Request Logger Middleware for Gin Framework

This is a middleware for Gin framework.

It uses zap to provide a log featurues in package.

Fork from https://github.com/karmadon/gin-request-logger

Like This project

Usage

Install

Download and install using go module:

go get github.com/fghpdf/gin-request-logger
Usage
package main

import (
  "fmt"
  "time"

  gin_request_logger "github.com/fghpdf/gin-request-logger"
  "github.com/gin-gonic/gin"
  "go.uber.org/zap"
)

func main() {
  r := gin.New()

  logger, _ := zap.NewProduction()

  r.Use(gin_request_logger.New(gin_request_logger.Options{
    LogResponse: true,
    Logger: logger
  }))

  // Example ping request.
  r.GET("/ping", func(c *gin.Context) {
    c.String(200, "pong "+fmt.Sprint(time.Now().Unix()))
  })

  // Example when panic happen.
  r.GET("/panic", func(c *gin.Context) {
    panic("An unexpected error happen!")
  })
  
  // Example post request
  r.GET("/post", func(c *gin.Context) {
    c.String(200, "Hello!")
  })

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

Documentation

Index

Constants

View Source
const RequestContextUUIDTag = "RequestUUID"

Variables

This section is empty.

Functions

func New

func New(options Options) gin.HandlerFunc

Types

type Options

type Options struct {
	LogResponse bool
	Logger      *zap.Logger
}

Jump to

Keyboard shortcuts

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