Files
warehouse-management-BE/internal/middlewares/logging_middleware.go
Tran Anh Tuan 6a4a96e0ca Base Project
2026-05-08 14:32:24 +07:00

35 lines
693 B
Go

package middlewares
import (
"time"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
)
func LoggingMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
start := time.Now()
log.Info().
Str("type", "request").
Str("method", c.Request.Method).
Str("path", c.Request.URL.Path).
Str("ip", c.ClientIP()).
Str("query", c.Request.URL.RawQuery).
Time("time", start).
Msg("incoming request")
c.Next()
log.Info().
Str("type", "response").
Str("method", c.Request.Method).
Str("path", c.Request.URL.Path).
Int("status", c.Writer.Status()).
Dur("latency", time.Since(start)).
Time("time", time.Now()).
Msg("outgoing response")
}
}