saasitone/pkg/log/log.go
Mike Stefanello 9acf73a4d9
Replace Echo logger with slog. (#67)
* Replace Echo logger with slog.
2024-06-14 21:01:48 -04:00

23 lines
483 B
Go

package log
import (
"log/slog"
"github.com/labstack/echo/v4"
"github.com/mikestefanello/pagoda/pkg/context"
)
// Set sets a logger in the context
func Set(ctx echo.Context, logger *slog.Logger) {
ctx.Set(context.LoggerKey, logger)
}
// Ctx returns the logger stored in context, or provides the default logger if one is not present
func Ctx(ctx echo.Context) *slog.Logger {
if l, ok := ctx.Get(context.LoggerKey).(*slog.Logger); ok {
return l
}
return slog.Default()
}