gin_logger.go 592 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package fslog
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "runtime/debug"
  5. "slices"
  6. "time"
  7. )
  8. func GinLogger(skipPaths []string) gin.HandlerFunc {
  9. return func(c *gin.Context) {
  10. start := time.Now()
  11. c.Next()
  12. path := c.Request.URL.Path
  13. if slices.Contains(skipPaths, path) {
  14. return
  15. }
  16. end := time.Now()
  17. Info(" %d | %d | %s | %s \"%s\"",
  18. c.Writer.Status(),
  19. end.Sub(start),
  20. c.ClientIP(),
  21. c.Request.Method,
  22. path,
  23. )
  24. }
  25. }
  26. func GinRecovery() gin.HandlerFunc {
  27. return func(c *gin.Context) {
  28. err := recover()
  29. if err != nil {
  30. Error("%s", debug.Stack())
  31. }
  32. }
  33. }