Files
Tim Wundenberg 1be46780bb
All checks were successful
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 1m19s
feat: extract into remaining packages
There has been a cyclic dependency.
transaction
	-> treasure_chest
	-> transaction_recurring
	-> transaction

This has been temporarily solved by moving the GenerateTransactions
function into the transaction package. In the future, this function has
to be rewritten to use a proper Service insteas of direct DB access or
replaced with a different system entirely.
2025-12-31 22:26:59 +01:00

51 lines
1.1 KiB
Go

package core
import (
"context"
"log/slog"
"os"
"go.opentelemetry.io/contrib/bridges/otelslog"
)
func NewLogPropagator() *slog.Logger {
return slog.New(&logHandler{
console: slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{}),
otel: otelslog.NewHandler("spend-sparrow"),
})
}
type logHandler struct {
console slog.Handler
otel slog.Handler
}
// Enabled implements slog.Handler.
func (l *logHandler) Enabled(ctx context.Context, level slog.Level) bool {
return l.console.Enabled(ctx, level)
}
// Handle implements slog.Handler.
func (l *logHandler) Handle(ctx context.Context, rec slog.Record) error {
if err := l.console.Handle(ctx, rec); err != nil {
return err
}
return l.otel.Handle(ctx, rec)
}
// WithAttrs implements slog.Handler.
func (l *logHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
return &logHandler{
console: l.console.WithAttrs(attrs),
otel: l.otel.WithAttrs(attrs),
}
}
// WithGroup implements slog.Handler.
func (l *logHandler) WithGroup(name string) slog.Handler {
return &logHandler{
console: l.console.WithGroup(name),
otel: l.otel.WithGroup(name),
}
}