1234567891011121314151617181920212223242526272829303132333435363738 |
- package fslog
- import (
- "github.com/gin-gonic/gin"
- "runtime/debug"
- "slices"
- "time"
- )
- func GinLogger(skipPaths []string) gin.HandlerFunc {
- return func(c *gin.Context) {
- start := time.Now()
- c.Next()
- path := c.Request.URL.Path
- if slices.Contains(skipPaths, path) {
- return
- }
- end := time.Now()
- Info(" %d | %d | %s | %s \"%s\"",
- c.Writer.Status(),
- end.Sub(start),
- c.ClientIP(),
- c.Request.Method,
- path,
- )
- }
- }
- func GinRecovery() gin.HandlerFunc {
- return func(c *gin.Context) {
- err := recover()
- if err != nil {
- Error("%s", debug.Stack())
- }
- }
- }
|