Improve client logging.
This commit is contained in:
@@ -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",
|
||||
|
Reference in New Issue
Block a user