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.With(map[string]string{ "CtxUserIP": userIP, "CtxUserPort": userPort, "KeyDomain": domain, "KeyPath": path, }) logger.Emit(models.InfoUser{ CtxUserIP: userIP, CtxUserPort: userPort, KeyPath: path, KeyDomain: domain, }) c.Locals(models.LoggerKey, logger) return c.Next() } }