diff --git a/README.md b/README.md index abfdac2..570c7d5 100644 --- a/README.md +++ b/README.md @@ -201,3 +201,56 @@ func main() { } } ``` + +## Custom `SkipPathRegexps` function + +Example for custom `SkipPathRegexps` function + +```go +rxURL := regexp.MustCompile(`^/ping\s*`) +r.Use(ginzap.GinzapWithConfig(logger, &ginzap.Config{ + UTC: true, + TimeFormat: time.RFC3339, + SkipPathRegexps: []*regexp.Regexp{rxURL}, +})) +``` + +Full example + +```go +package main + +import ( + "fmt" + "regexp" + "time" + + ginzap "github.com/gin-contrib/zap" + + "github.com/gin-gonic/gin" + "go.uber.org/zap" +) + +func main() { + r := gin.New() + + logger, _ := zap.NewProduction() + rxURL := regexp.MustCompile(`^/ping\s*`) + + r.Use(ginzap.GinzapWithConfig(logger, &ginzap.Config{ + UTC: true, + TimeFormat: time.RFC3339, + SkipPathRegexps: []*regexp.Regexp{rxURL}, + })) + + // Example ping request. + r.GET("/ping1234", func(c *gin.Context) { + c.String(200, "pong "+fmt.Sprint(time.Now().Unix())) + }) + + // Listen and Server in 0.0.0.0:8080 + if err := r.Run(":8080"); err != nil { + panic(err) + } +} +``` diff --git a/_example/example04/main.go b/_example/example04/main.go new file mode 100644 index 0000000..023a66e --- /dev/null +++ b/_example/example04/main.go @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "regexp" + "time" + + ginzap "github.com/gin-contrib/zap" + + "github.com/gin-gonic/gin" + "go.uber.org/zap" +) + +func main() { + r := gin.New() + + logger, _ := zap.NewProduction() + rxURL := regexp.MustCompile(`^/ping\s*`) + + r.Use(ginzap.GinzapWithConfig(logger, &ginzap.Config{ + UTC: true, + TimeFormat: time.RFC3339, + SkipPathRegexps: []*regexp.Regexp{rxURL}, + })) + + // Example ping request. + r.GET("/ping1234", func(c *gin.Context) { + c.String(200, "pong "+fmt.Sprint(time.Now().Unix())) + }) + + // Listen and Server in 0.0.0.0:8080 + if err := r.Run(":8080"); err != nil { + panic(err) + } +}