27 lines
459 B
Go
27 lines
459 B
Go
// internal/http/middleware/errorlog.go
|
|
package middleware
|
|
|
|
import (
|
|
"time"
|
|
|
|
"synlotto-website/internal/logging"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func ErrorLogger() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
start := time.Now()
|
|
c.Next()
|
|
|
|
if len(c.Errors) == 0 {
|
|
return
|
|
}
|
|
for _, e := range c.Errors {
|
|
logging.Info("❌ %s %s -> %d in %v: %v",
|
|
c.Request.Method, c.FullPath(), c.Writer.Status(),
|
|
time.Since(start), e.Err)
|
|
}
|
|
}
|
|
}
|