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

@ -6,6 +6,7 @@ import (
"github.com/labstack/echo/v4"
"github.com/mikestefanello/pagoda/pkg/context"
"github.com/mikestefanello/pagoda/pkg/controller"
"github.com/mikestefanello/pagoda/pkg/log"
"github.com/mikestefanello/pagoda/templates"
)
@ -18,17 +19,18 @@ func (e *Error) Page(err error, ctx echo.Context) {
return
}
// Determine the error status code
code := http.StatusInternalServerError
if he, ok := err.(*echo.HTTPError); ok {
code = he.Code
}
// Log the error
if code >= 500 {
ctx.Logger().Error(err)
} else {
ctx.Logger().Info(err)
log.Ctx(ctx).Error(err.Error())
}
// Render the error page
page := controller.NewPage(ctx)
page.Layout = templates.LayoutMain
page.Name = templates.PageError
@ -37,6 +39,8 @@ func (e *Error) Page(err error, ctx echo.Context) {
page.HTMX.Request.Enabled = false
if err = e.RenderPage(ctx, page); err != nil {
ctx.Logger().Error(err)
log.Ctx(ctx).Error("failed to render error page",
"error", err,
)
}
}