From cb3edfc32adbfbba96f64f3dea7fb6dd7ae8cf4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0lker=20G=2E=20=C3=96zt=C3=BCrk?= Date: Wed, 3 Feb 2021 13:36:15 +0300 Subject: [PATCH] feat(relayer): make Chain.logger configurable (#402) * feat(relayer): make Chain.logger configurable * fix tests --- cmd/config.go | 2 +- relayer/chain.go | 9 +++++++-- test/test_setup.go | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index 2966d3fef..8f4c7cdec 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -362,7 +362,7 @@ func validateConfig(c *Config) error { } for _, i := range c.Chains { - if err := i.Init(homePath, to, debug); err != nil { + if err := i.Init(homePath, to, nil, debug); err != nil { return fmt.Errorf("did you remember to run 'rly config init' error:%w", err) } } diff --git a/relayer/chain.go b/relayer/chain.go index 0d4ac4199..044a5e515 100644 --- a/relayer/chain.go +++ b/relayer/chain.go @@ -195,7 +195,7 @@ func (c *Chain) listenLoop(doneChan chan struct{}, tx, block, data bool) { // Init initializes the pieces of a chain that aren't set when it parses a config // NOTE: All validation of the chain should happen here. -func (c *Chain) Init(homePath string, timeout time.Duration, debug bool) error { +func (c *Chain) Init(homePath string, timeout time.Duration, logger log.Logger, debug bool) error { keybase, err := keys.New(c.ChainID, "test", keysDir(homePath, c.ChainID), nil) if err != nil { return err @@ -222,10 +222,15 @@ func (c *Chain) Init(homePath string, timeout time.Duration, debug bool) error { c.Client = client c.HomePath = homePath c.Encoding = encodingConfig - c.logger = defaultChainLogger() + c.logger = logger c.timeout = timeout c.debug = debug c.faucetAddrs = make(map[string]time.Time) + + if c.logger == nil { + c.logger = defaultChainLogger() + } + return nil } diff --git a/test/test_setup.go b/test/test_setup.go index 173e51ed4..ed4565b4b 100644 --- a/test/test_setup.go +++ b/test/test_setup.go @@ -121,7 +121,7 @@ func spinUpTestContainer(t *testing.T, rchan chan<- *dockertest.Resource, } // initialize the chain - require.NoError(t, c.Init(dir, tc.t.timeout, debug)) + require.NoError(t, c.Init(dir, tc.t.timeout, nil, debug)) // create the test key require.NoError(t, c.CreateTestKey())