星球狂想战队|Gin - 使用zap记录日志( 二 )

测试【星球狂想战队|Gin - 使用zap记录日志】package main?import ("fmt""time"?ginzap "github.com/gin-contrib/zap""github.com/gin-gonic/gin")?func main() {r := gin.New()?// logger, _ := zap.NewProduction()logger := InitLogger("debug", "console", "log.log")// 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("/now", func(c *gin.Context) {c.String(200, "现在时间:"+fmt.Sprint(time.Now()))})?// Example when panic happen.r.GET("/panic", func(c *gin.Context) {panic("An unexpected error happen!")})?// Listen and Server in 0.0.0.0:8080r.Run(":8080")}
星球狂想战队|Gin - 使用zap记录日志