From eb1f1b56d1519f17fc9ddf742891b98b5b8d3ebd Mon Sep 17 00:00:00 2001 From: Kai Lee Date: Thu, 27 Jun 2019 11:15:44 -0700 Subject: [PATCH] Replaced loggers in `node/` with custom shared logger --- node/contract.go | 5 ++--- node/node_newblock.go | 2 +- node/rpc.go | 11 ++++++----- node/worker/worker.go | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/node/contract.go b/node/contract.go index cad3d733b..3e92f108b 100644 --- a/node/contract.go +++ b/node/contract.go @@ -10,7 +10,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" "github.com/harmony-one/harmony/common/denominations" @@ -138,7 +137,7 @@ func (node *Node) getDeployedStakingContract() common.Address { func (node *Node) GetNonceOfAddress(address common.Address) uint64 { state, err := node.Blockchain().State() if err != nil { - log.Error("Failed to get chain state", "Error", err) + utils.GetLogger().Error("Failed to get chain state", "Error", err) return 0 } return state.GetNonce(address) @@ -148,7 +147,7 @@ func (node *Node) GetNonceOfAddress(address common.Address) uint64 { func (node *Node) GetBalanceOfAddress(address common.Address) (*big.Int, error) { state, err := node.Blockchain().State() if err != nil { - log.Error("Failed to get chain state", "Error", err) + utils.GetLogger().Error("Failed to get chain state", "Error", err) return nil, err } return state.GetBalance(address), nil diff --git a/node/node_newblock.go b/node/node_newblock.go index 9b4c29b26..ac63710e8 100644 --- a/node/node_newblock.go +++ b/node/node_newblock.go @@ -83,7 +83,7 @@ func (node *Node) WaitForConsensusReadyv2(readySignal chan struct{}, stopChan ch err = node.Worker.UpdateCurrent(coinbase) if err != nil { - log.Debug("Failed updating worker's state", "Error", err) + utils.GetLogger().Debug("Failed updating worker's state", "Error", err) continue } newBlock, err = node.Worker.Commit(sig, mask, viewID, coinbase) diff --git a/node/rpc.go b/node/rpc.go index d7b81360b..63d25eb7f 100644 --- a/node/rpc.go +++ b/node/rpc.go @@ -7,11 +7,12 @@ import ( "strings" "github.com/ethereum/go-ethereum/event" - "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rpc" + "github.com/harmony-one/harmony/hmy" "github.com/harmony-one/harmony/internal/hmyapi" "github.com/harmony-one/harmony/internal/hmyapi/filters" + "github.com/harmony-one/harmony/internal/utils" ) const ( @@ -81,7 +82,7 @@ func (node *Node) startHTTP(endpoint string, apis []rpc.API, modules []string, c return err } - log.Info("HTTP endpoint opened", "url", fmt.Sprintf("http://%s", endpoint), "cors", strings.Join(cors, ","), "vhosts", strings.Join(vhosts, ",")) + utils.GetLogger().Info("HTTP endpoint opened", "url", fmt.Sprintf("http://%s", endpoint), "cors", strings.Join(cors, ","), "vhosts", strings.Join(vhosts, ",")) // All listeners booted successfully httpListener = listener httpHandler = handler @@ -95,7 +96,7 @@ func (node *Node) stopHTTP() { httpListener.Close() httpListener = nil - log.Info("HTTP endpoint closed", "url", fmt.Sprintf("http://%s", httpEndpoint)) + utils.GetLogger().Info("HTTP endpoint closed", "url", fmt.Sprintf("http://%s", httpEndpoint)) } if httpHandler != nil { httpHandler.Stop() @@ -113,7 +114,7 @@ func (node *Node) startWS(endpoint string, apis []rpc.API, modules []string, wsO if err != nil { return err } - log.Info("WebSocket endpoint opened", "url", fmt.Sprintf("ws://%s", listener.Addr())) + utils.GetLogger().Info("WebSocket endpoint opened", "url", fmt.Sprintf("ws://%s", listener.Addr())) // All listeners booted successfully wsListener = listener wsHandler = handler @@ -127,7 +128,7 @@ func (node *Node) stopWS() { wsListener.Close() wsListener = nil - log.Info("WebSocket endpoint closed", "url", fmt.Sprintf("ws://%s", wsEndpoint)) + utils.GetLogger().Info("WebSocket endpoint closed", "url", fmt.Sprintf("ws://%s", wsEndpoint)) } if wsHandler != nil { wsHandler.Stop() diff --git a/node/worker/worker.go b/node/worker/worker.go index b74f05de7..5b2e995b0 100644 --- a/node/worker/worker.go +++ b/node/worker/worker.go @@ -5,7 +5,6 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" consensus_engine "github.com/harmony-one/harmony/consensus/engine" @@ -14,6 +13,7 @@ import ( "github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/vm" "github.com/harmony-one/harmony/internal/ctxerror" + "github.com/harmony-one/harmony/internal/utils" ) // environment is the worker's current environment and holds all of the current state information. @@ -61,7 +61,7 @@ func (w *Worker) SelectTransactionsForNewBlock(txs types.Transactions, maxNumTxs if err != nil { w.current.state.RevertToSnapshot(snap) invalid = append(invalid, tx) - log.Debug("Invalid transaction", "Error", err) + utils.GetLogger().Debug("Invalid transaction", "Error", err) } else { selected = append(selected, tx) }