All Projects → gin-contrib → Zap

gin-contrib / Zap

Licence: mit
Alternative logging through zap

Programming Languages

go
31211 projects - #10 most used programming language

Labels

Projects that are alternatives of or similar to Zap

Gin Cors
Cross Origin Resource Sharing middleware for gin-gonic
Stars: ✭ 107 (-23.02%)
Mutual labels:  gin
Chat Room
使用GO+Vue构建的聊天室网站
Stars: ✭ 113 (-18.71%)
Mutual labels:  gin
Go Http Metrics
Go modular http middleware to measure HTTP requests independent of metrics backend (with Prometheus and OpenCensus as backend implementations) and http framework/library
Stars: ✭ 128 (-7.91%)
Mutual labels:  gin
Gin Web
由gin + gorm + jwt + casbin组合实现的RBAC权限管理脚手架Golang版, 搭建完成即可快速、高效投入业务开发
Stars: ✭ 107 (-23.02%)
Mutual labels:  gin
Ultimate Go
This repo contains my notes on working with Go and computer systems.
Stars: ✭ 1,530 (+1000.72%)
Mutual labels:  gin
Zendea
A free, open-source, self-hosted forum software written in Go 官方QQ群:656868
Stars: ✭ 116 (-16.55%)
Mutual labels:  gin
Gin Template
golang template for gin framework!
Stars: ✭ 106 (-23.74%)
Mutual labels:  gin
Asgard
Asgarde Framework
Stars: ✭ 138 (-0.72%)
Mutual labels:  gin
Gzip
💾 Golang gzip middleware for Gin and net/http | Golang gzip中间件,支持Gin和net/http,开箱即用同时可定制
Stars: ✭ 113 (-18.71%)
Mutual labels:  gin
Gin bbs
Gin BBS App
Stars: ✭ 123 (-11.51%)
Mutual labels:  gin
Ugin
UGin is an API boilerplate written in Go (Golang) with Gin Framework.
Stars: ✭ 110 (-20.86%)
Mutual labels:  gin
Logrus
Hooks for logrus logging
Stars: ✭ 110 (-20.86%)
Mutual labels:  gin
Jwt Key Server
JWT based remote licensing server.
Stars: ✭ 123 (-11.51%)
Mutual labels:  gin
Gin
Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
Stars: ✭ 53,971 (+38728.06%)
Mutual labels:  gin
Gin Jwt
JWT Middleware for Gin framework
Stars: ✭ 1,957 (+1307.91%)
Mutual labels:  gin
Speedbump
A Redis-backed rate limiter in Go
Stars: ✭ 107 (-23.02%)
Mutual labels:  gin
Golang Gin Realworld Example App
Exemplary real world application built with Golang + Gin
Stars: ✭ 1,780 (+1180.58%)
Mutual labels:  gin
Gin Doc Cn
go 语言框架 gin 的中文文档
Stars: ✭ 1,918 (+1279.86%)
Mutual labels:  gin
Gin Rtsp
基于Gin + WebSocket + JSMpeg,在HTML页面上直接播放RTSP视频流。
Stars: ✭ 136 (-2.16%)
Mutual labels:  gin
Gin Swagger
gin middleware to automatically generate RESTful API documentation with Swagger 2.0.
Stars: ✭ 2,001 (+1339.57%)
Mutual labels:  gin

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

Usage

Start using it

Download and install it:

$ go get github.com/gin-contrib/zap

Import it in your code:

import "github.com/gin-contrib/zap"

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

	// Logs all panic to error log
	//   - stack means whether output the stack info.
	r.Use(ginzap.RecoveryWithZap(logger, true))

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

	// Listen and Server in 0.0.0.0:8080
	r.Run(":8080")
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].