feat: extract into remaining packages
All checks were successful
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 1m19s
All checks were successful
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 1m19s
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.
This commit is contained in:
50
internal/core/log.go
Normal file
50
internal/core/log.go
Normal file
@@ -0,0 +1,50 @@
|
||||
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),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user