ginzap

package module
v0.0.0-...-e99b6eb Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2017 License: MIT Imports: 4 Imported by: 0

README

zap

Build Status Go Report Card GoDoc

Alternative logging through zap. Thanks for Pull Request from @yezooz

Example

See the example.

package main

import (
	"fmt"
	"time"

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

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

	logger, _ := zap.NewProduction()

	// Add a ginzap middleware, which:
	//   - Logs all requests, like a combined access and error log.
	//   - Logs to stdout.
	//   - RFC3339 with UTC time format.
	r.Use(ginzap.Ginzap(logger, time.RFC3339, true))

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

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

Documentation

Overview

Package ginzap provides log handling using zap package. Code structure based on ginrus package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ginzap

func Ginzap(logger *zap.Logger, timeFormat string, utc bool) gin.HandlerFunc

Ginzap returns a gin.HandlerFunc (middleware) that logs requests using uber-go/zap on INFO level.

Requests with errors are logged using zap.Error(). Requests without errors are logged using zap.Info().

It receives:

  1. A time package format string (e.g. time.RFC3339).
  2. A boolean stating whether to use UTC time zone or local.

func OnLevel

func OnLevel(logger *zap.Logger, lvl zapcore.Level, timeFormat string, utc bool) gin.HandlerFunc

OnLevel returns a gin.HandlerFunc (middleware) that logs requests using uber-go/zap on the provided level.

Requests with errors are logged using zap.Error(). Requests without errors are logged using zap.Info().

It receives:

  1. A time package format string (e.g. time.RFC3339).
  2. A boolean stating whether to use UTC time zone or local.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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