Skip to content

Commit e6242bd

Browse files
committed
Use CTF logging lib
1 parent 4fd44a3 commit e6242bd

File tree

6 files changed

+33
-16
lines changed

6 files changed

+33
-16
lines changed

sentinel/internal/chain_poller/chain_poller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func NewChainPoller(cfg ChainPollerConfig) (*ChainPoller, error) {
3535
return nil, errors.New("chain ID not set")
3636
}
3737

38-
logger := cfg.Logger.With().Str("component", "ChainPoller").Logger().With().Int64("ChainID", cfg.ChainID).Logger()
38+
logger := cfg.Logger.With().Str("Component", "ChainPoller").Logger().With().Int64("ChainID", cfg.ChainID).Logger()
3939

4040
return &ChainPoller{
4141
blockchainClient: cfg.BlockchainClient,

sentinel/internal/chain_poller_service/chain_poller_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func NewChainPollerService(cfg ChainPollerServiceConfig) (*ChainPollerService, e
6969
return nil, fmt.Errorf("failed to initialize ChainPoller: %w", err)
7070
}
7171

72-
l := cfg.Logger.With().Str("component", "ChainPollerService").Logger().With().Int64("ChainID", cfg.ChainID).Logger()
72+
l := cfg.Logger.With().Str("Component", "ChainPollerService").Logger().With().Int64("ChainID", cfg.ChainID).Logger()
7373

7474
cfg.Logger = &l
7575

sentinel/internal/subscription_manager/subscription_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type SubscriptionManager struct {
3333

3434
// NewSubscriptionManager initializes a new SubscriptionManager.
3535
func NewSubscriptionManager(cfg SubscriptionManagerConfig) *SubscriptionManager {
36-
subscriptionManagerLogger := cfg.Logger.With().Str("component", "SubscriptionManager").Logger()
36+
subscriptionManagerLogger := cfg.Logger.With().Str("Component", "SubscriptionManager").Logger()
3737

3838
return &SubscriptionManager{
3939
registry: make(map[internal.EventKey][]chan api.Log),

sentinel/log.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// File: log.go
2+
package sentinel
3+
4+
import (
5+
"testing"
6+
7+
"github.com/rs/zerolog"
8+
"github.com/smartcontractkit/chainlink-testing-framework/lib/logging"
9+
)
10+
11+
const (
12+
LogLevelEnvVar = "SENTINEL_LOG_LEVEL"
13+
)
14+
15+
// GetLogger instantiates a logger that takes into account the test context and the log level
16+
func GetLogger(t *testing.T, componentName string) zerolog.Logger {
17+
return logging.GetLogger(t, LogLevelEnvVar).With().Str("Component", componentName).Logger()
18+
}

sentinel/sentinel.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package sentinel
44
import (
55
"fmt"
66
"sync"
7+
"testing"
78
"time"
89

910
"github.com/ethereum/go-ethereum/common"
@@ -14,7 +15,7 @@ import (
1415

1516
// SentinelConfig holds configuration for the Sentinel.
1617
type SentinelConfig struct {
17-
Logger zerolog.Logger
18+
t *testing.T
1819
}
1920

2021
type AddChainConfig struct {
@@ -24,18 +25,20 @@ type AddChainConfig struct {
2425
}
2526

2627
type Sentinel struct {
27-
config SentinelConfig
28+
l *zerolog.Logger
2829
mu sync.RWMutex
2930
services map[int64]*chain_poller_service.ChainPollerService // Map of chainID to ChianPollerService
3031
}
3132

3233
// NewSentinel initializes and returns a new Sentinel instance.
3334
func NewSentinel(cfg SentinelConfig) *Sentinel {
34-
cfg.Logger = cfg.Logger.With().Str("component", "Sentinel").Logger()
35-
cfg.Logger.Info().Msg("Initializing Sentinel")
35+
logger := GetLogger(cfg.t, "Sentinel")
36+
logger.Info().Msg("Initializing Sentinel")
37+
logger.Debug().Msg("Initializing Sentinel")
38+
logger.Info().Str("Level", logger.GetLevel().String()).Msg("Initializing Sentinel")
3639
return &Sentinel{
37-
config: cfg,
3840
services: make(map[int64]*chain_poller_service.ChainPollerService),
41+
l: &logger,
3942
}
4043
}
4144

@@ -51,7 +54,7 @@ func (s *Sentinel) AddChain(acc AddChainConfig) error {
5154
cfg := chain_poller_service.ChainPollerServiceConfig{
5255
PollInterval: acc.PollInterval,
5356
ChainID: acc.ChainID,
54-
Logger: &s.config.Logger,
57+
Logger: s.l,
5558
BlockchainClient: acc.BlockchainClient,
5659
}
5760

@@ -60,7 +63,7 @@ func (s *Sentinel) AddChain(acc AddChainConfig) error {
6063
return fmt.Errorf("failed to initialize ChainPollerService: %w", err)
6164
}
6265
s.services[cfg.ChainID] = eps
63-
s.config.Logger.Info().Int64("ChainID", cfg.ChainID).Msg("Added new chain")
66+
s.l.Info().Int64("ChainID", cfg.ChainID).Msg("Added new chain")
6467
eps.Start()
6568
return nil
6669
}
@@ -77,7 +80,7 @@ func (s *Sentinel) RemoveChain(chainID int64) error {
7780

7881
eps.Stop()
7982
delete(s.services, chainID)
80-
s.config.Logger.Info().Msg("Removed chain")
83+
s.l.Info().Msg("Removed chain")
8184
return nil
8285
}
8386

sentinel/sentinel_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,14 @@ import (
1010
"github.com/stretchr/testify/mock"
1111
"github.com/stretchr/testify/require"
1212

13-
"github.com/smartcontractkit/chainlink-testing-framework/lib/logging"
1413
"github.com/smartcontractkit/chainlink-testing-framework/sentinel/api"
1514
"github.com/smartcontractkit/chainlink-testing-framework/sentinel/internal"
1615
)
1716

1817
// Helper function to initialize a Sentinel instance for testing.
1918
func setupSentinel(t *testing.T) *Sentinel {
2019
t.Helper()
21-
logger := logging.GetTestLogger(t)
22-
s := NewSentinel(SentinelConfig{
23-
Logger: logger,
24-
})
20+
s := NewSentinel(SentinelConfig{t: t})
2521

2622
// Ensure Sentinel is closed after the test.
2723
t.Cleanup(func() {

0 commit comments

Comments
 (0)