dahankzter / zap

Alternative logging through zap

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

zap

Build Status Go Report Card GoDoc Join the chat at https://gitter.im/gin-gonic/gin

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")
}

About

Alternative logging through zap

License:MIT License


Languages

Language:Go 100.0%