Improve client logging.
Some checks failed
Linting and tests / Linting (push) Failing after 4s
Linting and tests / Tests (push) Failing after 3s

This commit is contained in:
2025-09-10 20:04:19 +05:00
parent e3b9c9ae40
commit c2142cc1a6
15 changed files with 118 additions and 44 deletions

View File

@@ -12,6 +12,7 @@ import (
type transaction struct {
transaction *sqlx.Tx
logger *slog.Logger
}
func (d *database) Transaction(ctx context.Context) (core.DatabaseTransaction, error) {
@@ -22,6 +23,7 @@ func (d *database) Transaction(ctx context.Context) (core.DatabaseTransaction, e
txHandler := &transaction{
transaction: txn,
logger: d.logger.With("module", "transactioner"),
}
return txHandler, nil
@@ -30,7 +32,7 @@ func (d *database) Transaction(ctx context.Context) (core.DatabaseTransaction, e
func (t *transaction) Apply(steps ...core.TransactionFunc) error {
for stepNumber, stepFunc := range steps {
if err := stepFunc(t.transaction); err != nil {
slog.Error(
t.logger.Error(
"Error occurred.",
"step", stepNumber,
"error", err.Error(),
@@ -39,7 +41,7 @@ func (t *transaction) Apply(steps ...core.TransactionFunc) error {
)
if rollbackErr := t.transaction.Rollback(); rollbackErr != nil {
slog.Error(
t.logger.Error(
"Transaction rollback failed.",
"error", err.Error(),
"module", "core/database",
@@ -54,7 +56,7 @@ func (t *transaction) Apply(steps ...core.TransactionFunc) error {
}
if err := t.transaction.Commit(); err != nil {
slog.Error(
t.logger.Error(
"Transaction commit failed.",
"error", err.Error(),
"module", "core/database",
@@ -62,7 +64,7 @@ func (t *transaction) Apply(steps ...core.TransactionFunc) error {
)
if rollbackErr := t.transaction.Rollback(); rollbackErr != nil {
slog.Error(
t.logger.Error(
"Transaction rollback failed.",
"error", err.Error(),
"module", "core/database",