diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-02-22 20:10:07 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-02-23 18:16:44 +0800 |
commit | d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851 (patch) | |
tree | 17c93170551d3eeabe2935de1765f157007f0dc2 /light | |
parent | 47af53f9aaf9aa7b12cd976eb150ccf3d64da6fd (diff) | |
download | dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.gz dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.bz2 dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.lz dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.xz dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.zst dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.zip |
all: blidly swap out glog to our log15, logs need rework
Diffstat (limited to 'light')
-rw-r--r-- | light/lightchain.go | 34 | ||||
-rw-r--r-- | light/odr_util.go | 6 | ||||
-rw-r--r-- | light/state.go | 10 | ||||
-rw-r--r-- | light/state_object.go | 21 | ||||
-rw-r--r-- | light/txpool.go | 15 |
5 files changed, 42 insertions, 44 deletions
diff --git a/light/lightchain.go b/light/lightchain.go index 0d28ad2f4..1f0fb9c34 100644 --- a/light/lightchain.go +++ b/light/lightchain.go @@ -17,6 +17,7 @@ package light import ( + "fmt" "math/big" "sync" "sync/atomic" @@ -27,8 +28,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/pow" "github.com/ethereum/go-ethereum/rlp" @@ -101,7 +101,7 @@ func NewLightChain(odr OdrBackend, config *params.ChainConfig, pow pow.PoW, mux if err != nil { return nil, err } - glog.V(logger.Info).Infoln("WARNING: Wrote default ethereum genesis block") + log.Info(fmt.Sprint("WARNING: Wrote default ethereum genesis block")) } if bc.genesisBlock.Hash() == (common.Hash{212, 229, 103, 64, 248, 118, 174, 248, 192, 16, 184, 106, 64, 213, 245, 103, 69, 161, 24, 208, 144, 106, 52, 230, 154, 236, 140, 13, 177, 203, 143, 163}) { @@ -117,7 +117,7 @@ func NewLightChain(odr OdrBackend, config *params.ChainConfig, pow pow.PoW, mux Root: common.HexToHash("c035076523faf514038f619715de404a65398c51899b5dccca9c05b00bc79315"), }) } - glog.V(logger.Info).Infoln("Added trusted CHT for mainnet") + log.Info(fmt.Sprint("Added trusted CHT for mainnet")) } else { if bc.genesisBlock.Hash() == (common.Hash{12, 215, 134, 162, 66, 93, 22, 241, 82, 198, 88, 49, 108, 66, 62, 108, 225, 24, 30, 21, 195, 41, 88, 38, 215, 201, 144, 76, 186, 156, 227, 3}) { // add trusted CHT for testnet @@ -125,7 +125,7 @@ func NewLightChain(odr OdrBackend, config *params.ChainConfig, pow pow.PoW, mux Number: 452, Root: common.HexToHash("511da2c88e32b14cf4a4e62f7fcbb297139faebc260a4ab5eb43cce6edcba324"), }) - glog.V(logger.Info).Infoln("Added trusted CHT for testnet") + log.Info(fmt.Sprint("Added trusted CHT for testnet")) } else { DeleteTrustedCht(bc.chainDb) } @@ -137,9 +137,9 @@ func NewLightChain(odr OdrBackend, config *params.ChainConfig, pow pow.PoW, mux // Check the current state of the block hashes and make sure that we do not have any of the bad blocks in our chain for hash := range core.BadHashes { if header := bc.GetHeaderByHash(hash); header != nil { - glog.V(logger.Error).Infof("Found bad hash, rewinding chain to block #%d [%x…]", header.Number, header.ParentHash[:4]) + log.Error(fmt.Sprintf("Found bad hash, rewinding chain to block #%d [%x…]", header.Number, header.ParentHash[:4])) bc.SetHead(header.Number.Uint64() - 1) - glog.V(logger.Error).Infoln("Chain rewind was successful, resuming normal operation") + log.Error(fmt.Sprint("Chain rewind was successful, resuming normal operation")) } } return bc, nil @@ -169,7 +169,7 @@ func (self *LightChain) loadLastState() error { // Issue a status log and return header := self.hc.CurrentHeader() headerTd := self.GetTd(header.Hash(), header.Number.Uint64()) - glog.V(logger.Info).Infof("Last header: #%d [%x…] TD=%v", self.hc.CurrentHeader().Number, self.hc.CurrentHeader().Hash().Bytes()[:4], headerTd) + log.Info(fmt.Sprintf("Last header: #%d [%x…] TD=%v", self.hc.CurrentHeader().Number, self.hc.CurrentHeader().Hash().Bytes()[:4], headerTd)) return nil } @@ -246,10 +246,10 @@ func (bc *LightChain) ResetWithGenesisBlock(genesis *types.Block) { // Prepare the genesis block and reinitialise the chain if err := core.WriteTd(bc.chainDb, genesis.Hash(), genesis.NumberU64(), genesis.Difficulty()); err != nil { - glog.Fatalf("failed to write genesis block TD: %v", err) + log.Crit(fmt.Sprintf("failed to write genesis block TD: %v", err)) } if err := core.WriteBlock(bc.chainDb, genesis); err != nil { - glog.Fatalf("failed to write genesis block: %v", err) + log.Crit(fmt.Sprintf("failed to write genesis block: %v", err)) } bc.genesisBlock = genesis bc.hc.SetGenesis(bc.genesisBlock.Header()) @@ -346,7 +346,7 @@ func (bc *LightChain) Stop() { bc.wg.Wait() - glog.V(logger.Info).Infoln("Chain manager stopped") + log.Info(fmt.Sprint("Chain manager stopped")) } // Rollback is designed to remove a chain of links from the database that aren't @@ -406,15 +406,15 @@ func (self *LightChain) InsertHeaderChain(chain []*types.Header, checkFreq int) switch status { case core.CanonStatTy: - if glog.V(logger.Debug) { - glog.Infof("[%v] inserted header #%d (%x...).\n", time.Now().UnixNano(), header.Number, header.Hash().Bytes()[0:4]) - } + log.Debug("", "msg", log.Lazy{Fn: func() string { + return fmt.Sprintf("[%v] inserted header #%d (%x...).\n", time.Now().UnixNano(), header.Number, header.Hash().Bytes()[0:4]) + }}) events = append(events, core.ChainEvent{Block: types.NewBlockWithHeader(header), Hash: header.Hash()}) case core.SideStatTy: - if glog.V(logger.Detail) { - glog.Infof("inserted forked header #%d (TD=%v) (%x...).\n", header.Number, header.Difficulty, header.Hash().Bytes()[0:4]) - } + log.Trace("", "msg", log.Lazy{Fn: func() string { + return fmt.Sprintf("inserted forked header #%d (TD=%v) (%x...).\n", header.Number, header.Difficulty, header.Hash().Bytes()[0:4]) + }}) events = append(events, core.ChainSideEvent{Block: types.NewBlockWithHeader(header)}) case core.SplitStatTy: diff --git a/light/odr_util.go b/light/odr_util.go index 761711621..e7f94db10 100644 --- a/light/odr_util.go +++ b/light/odr_util.go @@ -19,6 +19,7 @@ package light import ( "bytes" "errors" + "fmt" "math/big" "github.com/ethereum/go-ethereum/common" @@ -26,8 +27,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" "golang.org/x/net/context" ) @@ -149,7 +149,7 @@ func GetBody(ctx context.Context, odr OdrBackend, hash common.Hash, number uint6 } body := new(types.Body) if err := rlp.Decode(bytes.NewReader(data), body); err != nil { - glog.V(logger.Error).Infof("invalid block body RLP for hash %x: %v", hash, err) + log.Error(fmt.Sprintf("invalid block body RLP for hash %x: %v", hash, err)) return nil, err } return body, nil diff --git a/light/state.go b/light/state.go index f19748e89..1fb583c1d 100644 --- a/light/state.go +++ b/light/state.go @@ -17,12 +17,12 @@ package light import ( + "fmt" "math/big" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" "golang.org/x/net/context" ) @@ -239,9 +239,9 @@ func (self *LightState) GetOrNewStateObject(ctx context.Context, addr common.Add // newStateObject creates a state object whether it exists in the state or not func (self *LightState) newStateObject(addr common.Address) *StateObject { - if glog.V(logger.Debug) { - glog.Infof("(+) %x\n", addr) - } + log.Debug("", "msg", log.Lazy{Fn: func() string { + return fmt.Sprintf("(+) %x\n", addr) + }}) stateObject := NewStateObject(addr, self.odr) self.stateObjects[addr.Str()] = stateObject diff --git a/light/state_object.go b/light/state_object.go index e876c1566..03d4868cd 100644 --- a/light/state_object.go +++ b/light/state_object.go @@ -23,8 +23,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" "golang.org/x/net/context" ) @@ -109,9 +108,9 @@ func (self *StateObject) MarkForDeletion() { self.remove = true self.dirty = true - if glog.V(logger.Debug) { - glog.Infof("%x: #%d %v X\n", self.Address(), self.nonce, self.balance) - } + log.Debug("", "msg", log.Lazy{Fn: func() string { + return fmt.Sprintf("%x: #%d %v X\n", self.Address(), self.nonce, self.balance) + }}) } // getAddr gets the storage value at the given address from the trie @@ -158,18 +157,18 @@ func (self *StateObject) SetState(k, value common.Hash) { func (c *StateObject) AddBalance(amount *big.Int) { c.SetBalance(new(big.Int).Add(c.balance, amount)) - if glog.V(logger.Debug) { - glog.Infof("%x: #%d %v (+ %v)\n", c.Address(), c.nonce, c.balance, amount) - } + log.Debug("", "msg", log.Lazy{Fn: func() string { + return fmt.Sprintf("%x: #%d %v (+ %v)\n", c.Address(), c.nonce, c.balance, amount) + }}) } // SubBalance subtracts the given amount from the account balance func (c *StateObject) SubBalance(amount *big.Int) { c.SetBalance(new(big.Int).Sub(c.balance, amount)) - if glog.V(logger.Debug) { - glog.Infof("%x: #%d %v (- %v)\n", c.Address(), c.nonce, c.balance, amount) - } + log.Debug("", "msg", log.Lazy{Fn: func() string { + return fmt.Sprintf("%x: #%d %v (- %v)\n", c.Address(), c.nonce, c.balance, amount) + }}) } // SetBalance sets the account balance to the given amount diff --git a/light/txpool.go b/light/txpool.go index bcdb6123d..365f02d25 100644 --- a/light/txpool.go +++ b/light/txpool.go @@ -26,8 +26,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" "golang.org/x/net/context" @@ -321,7 +320,7 @@ func (pool *TxPool) eventLoop() { func (pool *TxPool) Stop() { close(pool.quit) pool.events.Unsubscribe() - glog.V(logger.Info).Infoln("Transaction pool stopped") + log.Info(fmt.Sprint("Transaction pool stopped")) } // Stats returns the number of currently pending (locally created) transactions @@ -417,7 +416,7 @@ func (self *TxPool) add(ctx context.Context, tx *types.Transaction) error { go self.eventMux.Post(core.TxPreEvent{Tx: tx}) } - if glog.V(logger.Debug) { + log.Debug("", "msg", log.Lazy{Fn: func() string { var toname string if to := tx.To(); to != nil { toname = common.Bytes2Hex(to[:4]) @@ -428,8 +427,8 @@ func (self *TxPool) add(ctx context.Context, tx *types.Transaction) error { // verified in ValidateTransaction. f, _ := types.Sender(self.signer, tx) from := common.Bytes2Hex(f[:4]) - glog.Infof("(t) %x => %s (%v) %x\n", from, toname, tx.Value, hash) - } + return fmt.Sprintf("(t) %x => %s (%v) %x\n", from, toname, tx.Value(), hash) + }}) return nil } @@ -464,11 +463,11 @@ func (self *TxPool) AddBatch(ctx context.Context, txs []*types.Transaction) { for _, tx := range txs { if err := self.add(ctx, tx); err != nil { - glog.V(logger.Debug).Infoln("tx error:", err) + log.Debug(fmt.Sprint("tx error:", err)) } else { sendTx = append(sendTx, tx) h := tx.Hash() - glog.V(logger.Debug).Infof("tx %x\n", h[:4]) + log.Debug(fmt.Sprintf("tx %x\n", h[:4])) } } |