Coder Social home page Coder Social logo

gin-zap's Introduction

Gin-Zap

Gin middleware for Logging with Zap, the structured, leveled logging framework from Uber

CircleCI Coverage Status Go Report Card GoDoc

Usage

Example

package main

import (
    "flag"
    "time"

    "github.com/uber-go/zap"
    "github.com/akath19/gin-zap"
    "github.com/gin-gonic/gin"
)

func main() {
    //Gin Router
    router := gin.New()
    //Zap logger
    zap := zap.NewProduction()
    //Add middleware to Gin, requires sync duration & zap pointer
    router.Use(ginzap.Logger(3 * time.Second, zap))
    //Other gin configs
    router.Use(gin.Recovery())

    //Logger will work outside Gin as well
    zap.Warn("Warning")
    zap.Error("Error")
    zap.Info("Info")

    //Start Gin
    router.Run(":8080")
}

Gin-Zap will produces lines in the following way:

[2018-08-06T14:27:43.001-0500] WARN [GIN] {"statusCode": 404, "latency": "1.232µs", "clientIP": "::1", "method": "GET", "path": "/png", "error": ""}

2018-08-06T14:27:43.262-0500 WARN [GIN] {"statusCode": 404, "latency": "60.356µs", "clientIP": "::1", "method": "GET", "path": "/favicon.ico", "error": ""}

2018-08-06T14:27:43.267-0500 WARN [GIN] {"statusCode": 404, "latency": "1.029µs", "clientIP": "::1", "method": "GET", "path": "/favicon.ico", "error": ""}

2018-08-06T14:27:45.397-0500 INFO [GIN] {"statusCode": 200, "latency": "98.698µs", "clientIP": "::1", "method": "GET", "path": "/ping", "error": ""} `

Contributing

All PRs are welcome!

  • Any PRs looking to improve test coverage will be greatly appreciated

License

See LICENSE file.

gin-zap's People

Contributors

akath19 avatar

Watchers

James Cloos avatar sssgun avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.