Files
GoMembership/internal/middlewares/logger_middleware.go
$(pass /github/name) de88a603d5 switched to gin-gonic
2024-07-11 12:28:39 +02:00

34 lines
581 B
Go

package middlewares
import (
"time"
"GoMembership/pkg/logger"
"github.com/gin-gonic/gin"
)
// LoggerMiddleware logs the incoming requests.
func LoggerMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
startTime := time.Now()
// Process the request
c.Next()
// Calculate the latency
latency := time.Since(startTime)
// Get the status code
statusCode := c.Writer.Status()
// Log the details
logger.Info.Printf("| %3d | %13v | %15s | %-7s %#v\n",
statusCode,
latency,
c.ClientIP(),
c.Request.Method,
c.Request.URL.Path,
)
}
}