customer/internal/utils/logger_middleware.go

29 lines
563 B
Go

package utils
import (
"github.com/gofiber/fiber/v2"
"github.com/themakers/hlog"
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
"strings"
)
func ContextLogger(logger hlog.Logger) fiber.Handler {
return func(c *fiber.Ctx) error {
userIP := c.IP()
userPort := c.Port()
domain := strings.Join(c.Subdomains(), "/")
path := c.Path()
logger.Emit(models.InfoUser{
CtxUserIP: userIP,
CtxUserPort: userPort,
KeyPath: path,
KeyDomain: domain,
})
c.Locals(models.LoggerKey, logger)
return c.Next()
}
}