Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

feat(BUX-199): unify logs #499

Merged
merged 15 commits into from
Dec 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore(BUX-199): remove more DebugLogs
pawellewandowski98 committed Dec 12, 2023
commit 40b97c94ead0e1efb58f835605123e911bcaa2c3
4 changes: 2 additions & 2 deletions examples/client/custom_models/example_model.go
Original file line number Diff line number Diff line change
@@ -53,11 +53,11 @@ func (e *Example) GetID() string {

// BeforeCreating is called before the model is saved to the DB
func (e *Example) BeforeCreating(_ context.Context) (err error) {
e.DebugLog("starting: " + e.Name() + " BeforeCreating hook...")
e.Client().Logger().Debug().Msgf("starting: %s BeforeCreating hook...", e.Name())

// Do something here!

e.DebugLog("end: " + e.Name() + " BeforeCreating hook")
e.Client().Logger().Debug().Msgf("end: %s BeforeCreating hook", e.Name())
return
}

4 changes: 3 additions & 1 deletion model_draft_transactions.go
Original file line number Diff line number Diff line change
@@ -134,7 +134,9 @@ func (m *DraftTransaction) GetModelTableName() string {
func (m *DraftTransaction) Save(ctx context.Context) (err error) {
if err = Save(ctx, m); err != nil {

m.DebugLog("save tx error: " + err.Error())
m.Client().Logger().Error().
Str("draftTxID", m.GetID()).
Msgf("save tx error: %s", err.Error())

// todo: run in a go routine?
// un-reserve the utxos
13 changes: 8 additions & 5 deletions model_save.go
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ package bux

import (
"context"
"fmt"
"time"

"github.com/mrz1836/go-datastore"
@@ -67,11 +66,13 @@ func Save(ctx context.Context, model ModelInterface) (err error) {
}

// Logs for saving models
model.DebugLog(fmt.Sprintf("saving %d models...", len(modelsToSave)))
model.Client().Logger().Debug().Msgf("saving %d models...", len(modelsToSave))

// Save all models (or fail!)
for index := range modelsToSave {
modelsToSave[index].DebugLog("starting to save model: " + modelsToSave[index].Name() + " id: " + modelsToSave[index].GetID())
modelsToSave[index].Client().Logger().Debug().
Str("modelID", modelsToSave[index].GetID()).
Msgf("starting to save model: %s", modelsToSave[index].Name())
if err = modelsToSave[index].Client().Datastore().SaveModel(
ctx, modelsToSave[index], tx, modelsToSave[index].IsNew(), false,
); err != nil {
@@ -81,7 +82,7 @@ func Save(ctx context.Context, model ModelInterface) (err error) {

// Commit all the model(s) if needed
if tx.CanCommit() {
model.DebugLog("committing db transaction...")
model.Client().Logger().Debug().Msg("committing db transaction...")
if err = tx.Commit(); err != nil {
return
}
@@ -122,7 +123,9 @@ func saveToCache(ctx context.Context, keys []string, model ModelInterface, ttl t
}
}
} else {
model.DebugLog("ignoring saveToCache: client or cachestore is missing")
model.Client().Logger().Debug().
Str("modelID", model.GetID()).
Msg("ignoring saveToCache: client or cachestore is missing")
}
return nil
}
1 change: 1 addition & 0 deletions model_sync_transactions.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package bux

import (
"context"

"github.com/mrz1836/go-datastore"
customTypes "github.com/mrz1836/go-datastore/custom_types"
)
5 changes: 2 additions & 3 deletions sync_tx_service.go
Original file line number Diff line number Diff line change
@@ -10,12 +10,11 @@ import (
"sync"
"time"

"github.com/BuxOrg/bux/chainstate"
"github.com/BuxOrg/bux/notifications"
"github.com/bitcoin-sv/go-paymail"
"github.com/mrz1836/go-datastore"
customTypes "github.com/mrz1836/go-datastore/custom_types"

"github.com/BuxOrg/bux/chainstate"
"github.com/BuxOrg/bux/notifications"
)

// processSyncTransactions will process sync transaction records