Giter Club home page Giter Club logo

gin-glog's Introduction

Gin-Glog

Gin middleware for Logging with glog. It is meant as drop in replacement for the default logger used in Gin.

Build Status Coverage Status Go Report Card GoDoc

Project Context and Features

When it comes to choosing a Go framework, there's a lot of confusion about what to use. The scene is very fragmented, and detailed comparisons of different frameworks are still somewhat rare. Meantime, how to handle dependencies and structure projects are big topics in the Go community. We've liked using Gin for its speed, accessibility, and usefulness in developing microservice architectures. In creating Gin-Glog, we wanted to take fuller advantage of Gin's capabilities and help other devs do likewise.

Gin-Glog replaces the default logger of Gin to use Glog.

How Glog is different compared to other loggers

Glog is an efficient pure Go implementation of leveled logs. If you use Glog, you do not use blocking calls for writing logs. A goroutine in the background will flush queued loglines into appropriate logfiles. It provides logrotation, maintains symlinks to current files and creates flags to your command line interface.

Requirements

Gin-Glog uses the following Go packages as dependencies:

  • github.com/gin-gonic/gin
  • github.com/golang/glog

Installation

Assuming you've installed Go and Gin, run this:

go get github.com/szuecs/gin-glog

Usage

Example

Start your webapp to log to STDERR and /tmp:

% ./webapp -log_dir="/tmp" -alsologtostderr -v=2
package main

import (
    "flag"
    "time"

    "github.com/golang/glog"
    "github.com/szuecs/gin-glog"
    "github.com/gin-gonic/gin"
)

func main() {
    flag.Parse()
    router := gin.New()
    router.Use(ginglog.Logger(3 * time.Second))
    //..
    router.Use(gin.Recovery())

    glog.Warning("warning")
    glog.Error("err")
    glog.Info("info")
    glog.V(2).Infoln("This line will be printed if you use -v=N with N >= 2.")

    router.Run(":8080")
}

STDERR output of the example above. Lines with prefix "[Gin-Debug]" are hardcoded output of Gin and will not appear in your logfile:

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

W0306 16:37:12.836001     367 main.go:18] warning
E0306 16:37:12.836335     367 main.go:19] err
I0306 16:37:12.836402     367 main.go:20] info
I0306 16:26:33.901278   32538 main.go:19] This line will be printed if you use -v=N with N >= 2.
[GIN-debug] Listening and serving HTTP on :8080

Synopsis

Glog will add the following flags to your binary:

-alsologtostderr
      log to standard error as well as files
-log_backtrace_at value
      when logging hits line file:N, emit a stack trace (default :0)
-log_dir string
      If non-empty, write log files in this directory
-logtostderr
      log to standard error instead of files
-stderrthreshold value
      logs at or above this threshold go to stderr
-v value
      log level for V logs
-vmodule value
      comma-separated list of pattern=N settings for file-filtered logging

Contributing/TODO

We welcome contributions from the community; just submit a pull request. To help you get started, here are some items that we'd love help with:

  • Remove hardcoded logs in Gin
  • the code base

Please use github issues as starting point for contributions, new ideas or bugreports.

Contact

Contributors

Thanks to:

  • <your name>

License

See LICENSE file.

gin-glog's People

Contributors

mikkeloscar avatar raffo avatar szuecs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gin-glog's Issues

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.