2024-06-14 18:01:48 -07:00
|
|
|
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"
|
2024-06-14 18:01:48 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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 {
|
2024-06-14 18:01:48 -07:00
|
|
|
return slog.Default()
|
|
|
|
}
|