diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-02-28 22:55:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-28 22:55:37 +0800 |
commit | 94c71c171f6c4de1f6f041bf1aadef2a377e10a3 (patch) | |
tree | dd4a0ddcc1f41268ab22eb50e5d0329855ab1196 /contracts | |
parent | 5f7826270c9e87509fd7731ec64953a5e4761de0 (diff) | |
parent | b117da2db3e2a7c557fa6f95c49aa041a973a563 (diff) | |
download | go-tangerine-94c71c171f6c4de1f6f041bf1aadef2a377e10a3.tar go-tangerine-94c71c171f6c4de1f6f041bf1aadef2a377e10a3.tar.gz go-tangerine-94c71c171f6c4de1f6f041bf1aadef2a377e10a3.tar.bz2 go-tangerine-94c71c171f6c4de1f6f041bf1aadef2a377e10a3.tar.lz go-tangerine-94c71c171f6c4de1f6f041bf1aadef2a377e10a3.tar.xz go-tangerine-94c71c171f6c4de1f6f041bf1aadef2a377e10a3.tar.zst go-tangerine-94c71c171f6c4de1f6f041bf1aadef2a377e10a3.zip |
Merge pull request #3723 from karalabe/logger-updates-2
Logger updates
Diffstat (limited to 'contracts')
-rw-r--r-- | contracts/chequebook/cheque.go | 28 | ||||
-rw-r--r-- | contracts/release/release.go | 17 |
2 files changed, 25 insertions, 20 deletions
diff --git a/contracts/chequebook/cheque.go b/contracts/chequebook/cheque.go index bae6f3393..945e56e86 100644 --- a/contracts/chequebook/cheque.go +++ b/contracts/chequebook/cheque.go @@ -37,6 +37,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/contracts/chequebook/contract" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" @@ -104,6 +105,8 @@ type Chequebook struct { txhash string // tx hash of last deposit tx threshold *big.Int // threshold that triggers autodeposit if not nil buffer *big.Int // buffer to keep on top of balance for fork protection + + log log.Logger // contextual logger with the contrac address embedded } func (self *Chequebook) String() string { @@ -135,11 +138,12 @@ func NewChequebook(path string, contractAddr common.Address, prvKey *ecdsa.Priva owner: transactOpts.From, contract: chbook, session: session, + log: log.New("contract", contractAddr), } if (contractAddr != common.Address{}) { self.setBalanceFromBlockChain() - log.Trace(fmt.Sprintf("new chequebook initialised from %s (owner: %v, balance: %s)", contractAddr.Hex(), self.owner.Hex(), self.balance.String())) + self.log.Trace("New chequebook initialised", "owner", self.owner, "balance", self.balance) } return } @@ -147,7 +151,7 @@ func NewChequebook(path string, contractAddr common.Address, prvKey *ecdsa.Priva func (self *Chequebook) setBalanceFromBlockChain() { balance, err := self.backend.BalanceAt(context.TODO(), self.contractAddr, nil) if err != nil { - log.Error(fmt.Sprintf("can't get balance: %v", err)) + log.Error("Failed to retrieve chequebook balance", "err", err) } else { self.balance.Set(balance) } @@ -160,7 +164,6 @@ func LoadChequebook(path string, prvKey *ecdsa.PrivateKey, backend Backend, chec if err != nil { return } - self, _ = NewChequebook(path, common.Address{}, prvKey, backend) err = json.Unmarshal(data, self) @@ -170,8 +173,7 @@ func LoadChequebook(path string, prvKey *ecdsa.PrivateKey, backend Backend, chec if checkBalance { self.setBalanceFromBlockChain() } - - log.Trace(fmt.Sprintf("loaded chequebook (%s, owner: %v, balance: %v) initialised from %v", self.contractAddr.Hex(), self.owner.Hex(), self.balance, path)) + log.Trace("Loaded chequebook from disk", "path", path) return } @@ -226,7 +228,7 @@ func (self *Chequebook) Save() (err error) { if err != nil { return err } - log.Trace(fmt.Sprintf("saving chequebook (%s) to %v", self.contractAddr.Hex(), self.path)) + self.log.Trace("Saving chequebook to disk", self.path) return ioutil.WriteFile(self.path, data, os.ModePerm) } @@ -339,12 +341,12 @@ func (self *Chequebook) deposit(amount *big.Int) (string, error) { chbookRaw := &contract.ChequebookRaw{Contract: self.contract} tx, err := chbookRaw.Transfer(depositTransactor) if err != nil { - log.Warn(fmt.Sprintf("error depositing %d wei to chequebook (%s, balance: %v, target: %v): %v", amount, self.contractAddr.Hex(), self.balance, self.buffer, err)) + self.log.Warn("Failed to fund chequebook", "amount", amount, "balance", self.balance, "target", self.buffer, "err", err) return "", err } // assume that transaction is actually successful, we add the amount to balance right away self.balance.Add(self.balance, amount) - log.Trace(fmt.Sprintf("deposited %d wei to chequebook (%s, balance: %v, target: %v)", amount, self.contractAddr.Hex(), self.balance, self.buffer)) + self.log.Trace("Deposited funds to chequebook", "amount", amount, "balance", self.balance, "target", self.buffer) return tx.Hash().Hex(), nil } @@ -440,6 +442,7 @@ type Inbox struct { maxUncashed *big.Int // threshold that triggers autocashing cashed *big.Int // cumulative amount cashed cheque *Cheque // last cheque, nil if none yet received + log log.Logger // contextual logger with the contrac address embedded } // NewInbox creates an Inbox. An Inboxes is not persisted, the cumulative sum is updated @@ -467,8 +470,9 @@ func NewInbox(prvKey *ecdsa.PrivateKey, contractAddr, beneficiary common.Address signer: signer, session: session, cashed: new(big.Int).Set(common.Big0), + log: log.New("contract", contractAddr), } - log.Trace(fmt.Sprintf("initialised inbox (%s -> %s) expected signer: %x", self.contract.Hex(), self.beneficiary.Hex(), crypto.FromECDSAPub(signer))) + self.log.Trace("New chequebook inbox initialized", "beneficiary", self.beneficiary, "signer", hexutil.Bytes(crypto.FromECDSAPub(signer))) return } @@ -490,7 +494,7 @@ func (self *Inbox) Stop() { func (self *Inbox) Cash() (txhash string, err error) { if self.cheque != nil { txhash, err = self.cheque.Cash(self.session) - log.Trace(fmt.Sprintf("cashing cheque (total: %v) on chequebook (%s) sending to %v", self.cheque.Amount, self.contract.Hex(), self.beneficiary.Hex())) + self.log.Trace("Cashing in chequebook cheque", "amount", self.cheque.Amount, "beneficiary", self.beneficiary) self.cashed = self.cheque.Amount } return @@ -574,7 +578,7 @@ func (self *Inbox) Receive(promise swap.Promise) (*big.Int, error) { self.Cash() } } - log.Trace(fmt.Sprintf("received cheque of %v wei in inbox (%s, uncashed: %v)", amount, self.contract.Hex(), uncashed)) + self.log.Trace("Received cheque in chequebook inbox", "amount", amount, "uncashed", uncashed) } return amount, err @@ -582,7 +586,7 @@ func (self *Inbox) Receive(promise swap.Promise) (*big.Int, error) { // Verify verifies cheque for signer, contract, beneficiary, amount, valid signature. func (self *Cheque) Verify(signerKey *ecdsa.PublicKey, contract, beneficiary common.Address, sum *big.Int) (*big.Int, error) { - log.Trace(fmt.Sprintf("verify cheque: %v - sum: %v", self, sum)) + log.Trace("Verifying chequebook cheque", "cheque", self, "sum", sum) if sum == nil { return nil, fmt.Errorf("invalid amount") } diff --git a/contracts/release/release.go b/contracts/release/release.go index 7b63059d0..613e62aa9 100644 --- a/contracts/release/release.go +++ b/contracts/release/release.go @@ -127,10 +127,10 @@ func (r *ReleaseService) checker() { version, err := r.oracle.CurrentVersion(opts) if err != nil { if err == bind.ErrNoCode { - log.Debug(fmt.Sprintf("Release oracle not found at %x", r.config.Oracle)) + log.Debug("Release oracle not found", "contract", r.config.Oracle) continue } - log.Error(fmt.Sprintf("Failed to retrieve current release: %v", err)) + log.Error("Failed to retrieve current release", "err", err) continue } // Version was successfully retrieved, notify if newer than ours @@ -143,13 +143,14 @@ func (r *ReleaseService) checker() { howtofix := fmt.Sprintf("Please check https://github.com/ethereum/go-ethereum/releases for new releases") separator := strings.Repeat("-", len(warning)) - log.Warn(fmt.Sprint(separator)) - log.Warn(fmt.Sprint(warning)) - log.Warn(fmt.Sprint(howtofix)) - log.Warn(fmt.Sprint(separator)) + log.Warn(separator) + log.Warn(warning) + log.Warn(howtofix) + log.Warn(separator) } else { - log.Debug(fmt.Sprintf("Client v%d.%d.%d-%x seems up to date with upstream v%d.%d.%d-%x", - r.config.Major, r.config.Minor, r.config.Patch, r.config.Commit[:4], version.Major, version.Minor, version.Patch, version.Commit[:4])) + log.Debug("Client seems up to date with upstream", + "local", fmt.Sprintf("v%d.%d.%d-%x", r.config.Major, r.config.Minor, r.config.Patch, r.config.Commit[:4]), + "upstream", fmt.Sprintf("v%d.%d.%d-%x", version.Major, version.Minor, version.Patch, version.Commit[:4])) } // If termination was requested, return |