saasitone/pkg/log/log.go

29 lines
579 B
Go
Raw Permalink Normal View History

package log
import (
"log/slog"
"github.com/labstack/echo/v4"
2024-07-09 17:57:05 -07:00
"git.grosinger.net/tgrosinger/saasitone/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
}
2024-06-19 06:32:22 -07:00
return Default()
}
// Default returns the default logger
func Default() *slog.Logger {
return slog.Default()
}