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

Commit

Permalink
Minor changes for logger
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Apr 14, 2022
1 parent a4d744b commit 754f074
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
8 changes: 5 additions & 3 deletions client_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ func (c *Client) loadDatastore(ctx context.Context) (err error) {
}

// Load client (runs ALL options, IE: auto migrate models)
c.options.dataStore.ClientInterface, err = datastore.NewClient(
ctx, c.options.dataStore.options...,
)
if c.options.dataStore.ClientInterface == nil {
c.options.dataStore.ClientInterface, err = datastore.NewClient(
ctx, c.options.dataStore.options...,
)
}
return
}

Expand Down
16 changes: 4 additions & 12 deletions client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,10 @@ func WithDebugging() ClientOps {
c.debug = true

// Enable debugging on other services
if c.chainstate != nil {
c.chainstate.options = append(c.chainstate.options, chainstate.WithDebugging())
}
if c.cacheStore != nil {
c.cacheStore.options = append(c.cacheStore.options, cachestore.WithDebugging())
}
if c.dataStore != nil {
c.dataStore.options = append(c.dataStore.options, datastore.WithDebugging())
}
if c.taskManager != nil {
c.taskManager.options = append(c.taskManager.options, taskmanager.WithDebugging())
}
c.cacheStore.options = append(c.cacheStore.options, cachestore.WithDebugging())
c.chainstate.options = append(c.chainstate.options, chainstate.WithDebugging())
c.dataStore.options = append(c.dataStore.options, datastore.WithDebugging())
c.taskManager.options = append(c.taskManager.options, taskmanager.WithDebugging())
}
}

Expand Down
12 changes: 6 additions & 6 deletions datastore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func NewClient(ctx context.Context, opts ...ClientOps) (ClientInterface, error)
opt(client.options)
}

// Set logger if not set now
if client.options.logger == nil {
client.options.logger = newBasicLogger(client.IsDebug())
}

// EMPTY! Engine was NOT set and will use the default (file based)
if client.Engine().IsEmpty() {

Expand Down Expand Up @@ -105,11 +110,6 @@ func NewClient(ctx context.Context, opts ...ClientOps) (ClientInterface, error)
}
}

// Set logger if not set now
if client.options.logger == nil {
client.options.logger = newBasicLogger(client.IsDebug())
}

// Return the client
return client, nil
}
Expand Down Expand Up @@ -159,7 +159,7 @@ func (c *Client) IsNewRelicEnabled() bool {

// DebugLog will display verbose logs
func (c *Client) DebugLog(text string) {
if c.options.debug && c.options.logger != nil {
if c.IsDebug() && c.options.logger != nil {
c.options.logger.Info(context.Background(), text)
}
}
Expand Down

0 comments on commit 754f074

Please sign in to comment.