Replace Echo logger with slog. (#67)

* Replace Echo logger with slog.
This commit is contained in:
Mike Stefanello 2024-06-14 21:01:48 -04:00 committed by GitHub
parent 97bef0257e
commit c8a3d64918
14 changed files with 315 additions and 57 deletions

View file

@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"log/slog"
"entgo.io/ent/dialect"
entsql "entgo.io/ent/dialect/sql"
@ -12,8 +13,6 @@ import (
// Required by ent
_ "github.com/jackc/pgx/v4/stdlib"
"github.com/labstack/echo/v4"
"github.com/labstack/gommon/log"
"github.com/mikestefanello/pagoda/config"
"github.com/mikestefanello/pagoda/ent"
@ -96,6 +95,14 @@ func (c *Container) initConfig() {
panic(fmt.Sprintf("failed to load config: %v", err))
}
c.Config = &cfg
// Configure logging
switch cfg.App.Environment {
case config.EnvProduction:
slog.SetLogLoggerLevel(slog.LevelInfo)
default:
slog.SetLogLoggerLevel(slog.LevelDebug)
}
}
// initValidator initializes the validator
@ -106,15 +113,7 @@ func (c *Container) initValidator() {
// initWeb initializes the web framework
func (c *Container) initWeb() {
c.Web = echo.New()
// Configure logging
switch c.Config.App.Environment {
case config.EnvProduction:
c.Web.Logger.SetLevel(log.WARN)
default:
c.Web.Logger.SetLevel(log.DEBUG)
}
c.Web.HideBanner = true
c.Web.Validator = c.Validator
}

View file

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/mikestefanello/pagoda/config"
"github.com/mikestefanello/pagoda/pkg/log"
"github.com/labstack/echo/v4"
)
@ -84,7 +85,9 @@ func (m *MailClient) send(email *mail, ctx echo.Context) error {
// Check if mail sending should be skipped
if m.skipSend() {
ctx.Logger().Debugf("skipping email sent to: %s", email.to)
log.Ctx(ctx).Debug("skipping email delivery",
"to", email.to,
)
return nil
}