31 lines
580 B
Go
31 lines
580 B
Go
package middlewares
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/drama-generator/backend/pkg/logger"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func LoggerMiddleware(log *logger.Logger) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
start := time.Now()
|
|
path := c.Request.URL.Path
|
|
query := c.Request.URL.RawQuery
|
|
|
|
c.Next()
|
|
|
|
duration := time.Since(start)
|
|
|
|
log.Infow("HTTP Request",
|
|
"method", c.Request.Method,
|
|
"path", path,
|
|
"query", query,
|
|
"status", c.Writer.Status(),
|
|
"duration", duration.Milliseconds(),
|
|
"ip", c.ClientIP(),
|
|
"user_agent", c.Request.UserAgent(),
|
|
)
|
|
}
|
|
}
|