Files
gochat/internal/middleware/logger.go
T
2026-06-04 15:44:48 +08:00

29 lines
558 B
Go

package middleware
import (
"time"
"github.com/gin-gonic/gin"
applogger "github.com/gochat/gochat/pkg/logger"
)
// RequestLogger logs structured request information.
// Pattern follows Chatwoot's Rails request logging middleware.
func RequestLogger() gin.HandlerFunc {
return func(c *gin.Context) {
start := time.Now()
path := c.Request.URL.Path
method := c.Request.Method
c.Next()
latency := time.Since(start)
status := c.Writer.Status()
applogger.L().Infof("HTTP %s %s %d %v",
method, path, status, latency)
c.Next()
}
}