|
@@ -1,19 +1,38 @@
|
|
package fslog
|
|
package fslog
|
|
|
|
|
|
import (
|
|
import (
|
|
- ginzap "github.com/gin-contrib/zap"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
|
|
+ "runtime/debug"
|
|
|
|
+ "slices"
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
func GinLogger(skipPaths []string) gin.HandlerFunc {
|
|
func GinLogger(skipPaths []string) gin.HandlerFunc {
|
|
- return ginzap.GinzapWithConfig(log.logger.Desugar(), &ginzap.Config{
|
|
|
|
- TimeFormat: time.RFC3339,
|
|
|
|
- UTC: true,
|
|
|
|
- SkipPaths: skipPaths,
|
|
|
|
- })
|
|
|
|
|
|
+ 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 {
|
|
func GinRecovery() gin.HandlerFunc {
|
|
- return ginzap.RecoveryWithZap(log.logger.Desugar(), true)
|
|
|
|
|
|
+ return func(c *gin.Context) {
|
|
|
|
+ err := recover()
|
|
|
|
+ if err != nil {
|
|
|
|
+ Error("%s", debug.Stack())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|