Skip to content

Commit e588e0c

Browse files
committed
all: next batch of log polishes to contextual versions
1 parent d4f60d3 commit e588e0c

18 files changed

Lines changed: 203 additions & 242 deletions

File tree

‎accounts/abi/bind/util.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func WaitMined(ctx context.Context, b DeployBackend, tx *types.Transaction) (*ty
3232
queryTicker := time.NewTicker(time.Second)
3333
defer queryTicker.Stop()
3434

35-
logger := log.New("hash", tx.Hash().Hex()[:8])
35+
logger := log.New("hash", tx.Hash())
3636
for {
3737
receipt, err := b.TransactionReceipt(ctx, tx.Hash())
3838
if receipt != nil {

‎accounts/keystore/account_cache.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func (ac *accountCache) scan() ([]accounts.Account, error) {
262262
case err != nil:
263263
logger.Debug("Failed to decode keystore key", "err", err)
264264
case (addr == common.Address{}):
265-
logger.Debug("Failed to decode keystore key", "error", "missing or zero address")
265+
logger.Debug("Failed to decode keystore key", "err", "missing or zero address")
266266
default:
267267
addrs = append(addrs, accounts.Account{Address: addr, URL: accounts.URL{Scheme: KeyStoreScheme, Path: path}})
268268
}

‎accounts/usbwallet/ledger_hub.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (hub *LedgerHub) refreshWallets() {
121121
}
122122
// If there are no more wallets or the device is before the next, wrap new wallet
123123
if len(hub.wallets) == 0 || hub.wallets[0].URL().Cmp(url) > 0 {
124-
wallet := &ledgerWallet{url: &url, info: ledger, logger: log.New("url", url)}
124+
wallet := &ledgerWallet{url: &url, info: ledger, log: log.New("url", url)}
125125

126126
events = append(events, accounts.WalletEvent{Wallet: wallet, Arrive: true})
127127
wallets = append(wallets, wallet)

‎accounts/usbwallet/ledger_wallet.go‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ type ledgerWallet struct {
124124
commsLock chan struct{} // Mutex (buf=1) for the USB comms without keeping the state locked
125125
stateLock sync.RWMutex // Protects read and write access to the wallet struct fields
126126

127-
logger log.Logger // Contextual logger to tag the ledger with its id
127+
log log.Logger // Contextual logger to tag the ledger with its id
128128
}
129129

130130
// URL implements accounts.Wallet, returning the URL of the Ledger device.
@@ -222,8 +222,8 @@ func (w *ledgerWallet) Open(passphrase string) error {
222222
// - libusb on Windows doesn't support hotplug, so we can't detect USB unplugs
223223
// - communication timeout on the Ledger requires a device power cycle to fix
224224
func (w *ledgerWallet) heartbeat() {
225-
w.logger.Debug("Ledger health-check started")
226-
defer w.logger.Debug("Ledger health-check stopped")
225+
w.log.Debug("Ledger health-check started")
226+
defer w.log.Debug("Ledger health-check stopped")
227227

228228
// Execute heartbeat checks until termination or error
229229
var (
@@ -262,7 +262,7 @@ func (w *ledgerWallet) heartbeat() {
262262
}
263263
// In case of error, wait for termination
264264
if err != nil {
265-
w.logger.Debug("Ledger health-check failed", "err", err)
265+
w.log.Debug("Ledger health-check failed", "err", err)
266266
errc = <-w.healthQuit
267267
}
268268
errc <- err
@@ -350,8 +350,8 @@ func (w *ledgerWallet) Accounts() []accounts.Account {
350350
// selfDerive is an account derivation loop that upon request attempts to find
351351
// new non-zero accounts.
352352
func (w *ledgerWallet) selfDerive() {
353-
w.logger.Debug("Ledger self-derivation started")
354-
defer w.logger.Debug("Ledger self-derivation stopped")
353+
w.log.Debug("Ledger self-derivation started")
354+
defer w.log.Debug("Ledger self-derivation stopped")
355355

356356
// Execute self-derivations until termination or error
357357
var (
@@ -396,7 +396,7 @@ func (w *ledgerWallet) selfDerive() {
396396
// Retrieve the next derived Ethereum account
397397
if nextAddr == (common.Address{}) {
398398
if nextAddr, err = w.ledgerDerive(nextPath); err != nil {
399-
w.logger.Warn("Ledger account derivation failed", "err", err)
399+
w.log.Warn("Ledger account derivation failed", "err", err)
400400
break
401401
}
402402
}
@@ -407,12 +407,12 @@ func (w *ledgerWallet) selfDerive() {
407407
)
408408
balance, err = w.deriveChain.BalanceAt(context, nextAddr, nil)
409409
if err != nil {
410-
w.logger.Warn("Ledger balance retrieval failed", "err", err)
410+
w.log.Warn("Ledger balance retrieval failed", "err", err)
411411
break
412412
}
413413
nonce, err = w.deriveChain.NonceAt(context, nextAddr, nil)
414414
if err != nil {
415-
w.logger.Warn("Ledger nonce retrieval failed", "err", err)
415+
w.log.Warn("Ledger nonce retrieval failed", "err", err)
416416
break
417417
}
418418
// If the next account is empty, stop self-derivation, but add it nonetheless
@@ -432,7 +432,7 @@ func (w *ledgerWallet) selfDerive() {
432432

433433
// Display a log message to the user for new (or previously empty accounts)
434434
if _, known := w.paths[nextAddr]; !known || (!empty && nextAddr == w.deriveNextAddr) {
435-
w.logger.Info("Ledger discovered new account", "address", nextAddr.Hex(), "path", path, "balance", balance, "nonce", nonce)
435+
w.log.Info("Ledger discovered new account", "address", nextAddr, "path", path, "balance", balance, "nonce", nonce)
436436
}
437437
// Fetch the next potential account
438438
if !empty {
@@ -471,7 +471,7 @@ func (w *ledgerWallet) selfDerive() {
471471
}
472472
// In case of error, wait for termination
473473
if err != nil {
474-
w.logger.Debug("Ledger self-derivation failed", "err", err)
474+
w.log.Debug("Ledger self-derivation failed", "err", err)
475475
errc = <-w.deriveQuit
476476
}
477477
errc <- err
@@ -851,7 +851,7 @@ func (w *ledgerWallet) ledgerExchange(opcode ledgerOpcode, p1 ledgerParam1, p2 l
851851
apdu = nil
852852
}
853853
// Send over to the device
854-
w.logger.Trace("Data chunk sent to the Ledger", "chunk", hexutil.Bytes(chunk))
854+
w.log.Trace("Data chunk sent to the Ledger", "chunk", hexutil.Bytes(chunk))
855855
if _, err := w.device.Write(chunk); err != nil {
856856
return nil, err
857857
}
@@ -864,7 +864,7 @@ func (w *ledgerWallet) ledgerExchange(opcode ledgerOpcode, p1 ledgerParam1, p2 l
864864
if _, err := io.ReadFull(w.device, chunk); err != nil {
865865
return nil, err
866866
}
867-
w.logger.Trace("Data chunk received from the Ledger", "chunk", hexutil.Bytes(chunk))
867+
w.log.Trace("Data chunk received from the Ledger", "chunk", hexutil.Bytes(chunk))
868868

869869
// Make sure the transport header matches
870870
if chunk[0] != 0x01 || chunk[1] != 0x01 || chunk[2] != 0x05 {

‎common/types.go‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ func StringToHash(s string) Hash { return BytesToHash([]byte(s)) }
4747
func BigToHash(b *big.Int) Hash { return BytesToHash(b.Bytes()) }
4848
func HexToHash(s string) Hash { return BytesToHash(FromHex(s)) }
4949

50-
// Don't use the default 'String' method in case we want to overwrite
51-
5250
// Get the string representation of the underlying hash
5351
func (h Hash) Str() string { return string(h[:]) }
5452
func (h Hash) Bytes() []byte { return h[:] }
@@ -144,6 +142,17 @@ func (a Address) Big() *big.Int { return new(big.Int).SetBytes(a[:]) }
144142
func (a Address) Hash() Hash { return BytesToHash(a[:]) }
145143
func (a Address) Hex() string { return hexutil.Encode(a[:]) }
146144

145+
// String implements the stringer interface and is used also by the logger.
146+
func (a Address) String() string {
147+
return a.Hex()
148+
}
149+
150+
// Format implements fmt.Formatter, forcing the byte slice to be formatted as is,
151+
// without going through the stringer interface used for logging.
152+
func (a Address) Format(s fmt.State, c rune) {
153+
fmt.Fprintf(s, "%"+string(c), a[:])
154+
}
155+
147156
// Sets the address to the value of b. If b is larger than len(a) it will panic
148157
func (a *Address) SetBytes(b []byte) {
149158
if len(b) > len(a) {

‎console/bridge.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func setError(resp *otto.Object, code int, msg string) {
305305
func throwJSException(msg interface{}) otto.Value {
306306
val, err := otto.ToValue(msg)
307307
if err != nil {
308-
log.Error(fmt.Sprintf("Failed to serialize JavaScript exception %v: %v", msg, err))
308+
log.Error("Failed to serialize JavaScript exception", "exception", msg, "err", err)
309309
}
310310
panic(val)
311311
}

‎contracts/chequebook/cheque.go‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737

3838
"github.com/ethereum/go-ethereum/accounts/abi/bind"
3939
"github.com/ethereum/go-ethereum/common"
40+
"github.com/ethereum/go-ethereum/common/hexutil"
4041
"github.com/ethereum/go-ethereum/contracts/chequebook/contract"
4142
"github.com/ethereum/go-ethereum/core/types"
4243
"github.com/ethereum/go-ethereum/crypto"
@@ -104,6 +105,8 @@ type Chequebook struct {
104105
txhash string // tx hash of last deposit tx
105106
threshold *big.Int // threshold that triggers autodeposit if not nil
106107
buffer *big.Int // buffer to keep on top of balance for fork protection
108+
109+
log log.Logger // contextual logger with the contrac address embedded
107110
}
108111

109112
func (self *Chequebook) String() string {
@@ -135,19 +138,20 @@ func NewChequebook(path string, contractAddr common.Address, prvKey *ecdsa.Priva
135138
owner: transactOpts.From,
136139
contract: chbook,
137140
session: session,
141+
log: log.New("contract", contractAddr),
138142
}
139143

140144
if (contractAddr != common.Address{}) {
141145
self.setBalanceFromBlockChain()
142-
log.Trace(fmt.Sprintf("new chequebook initialised from %s (owner: %v, balance: %s)", contractAddr.Hex(), self.owner.Hex(), self.balance.String()))
146+
self.log.Trace("New chequebook initialised", "owner", self.owner, "balance", self.balance)
143147
}
144148
return
145149
}
146150

147151
func (self *Chequebook) setBalanceFromBlockChain() {
148152
balance, err := self.backend.BalanceAt(context.TODO(), self.contractAddr, nil)
149153
if err != nil {
150-
log.Error(fmt.Sprintf("can't get balance: %v", err))
154+
log.Error("Failed to retrieve chequebook balance", "err", err)
151155
} else {
152156
self.balance.Set(balance)
153157
}
@@ -160,7 +164,6 @@ func LoadChequebook(path string, prvKey *ecdsa.PrivateKey, backend Backend, chec
160164
if err != nil {
161165
return
162166
}
163-
164167
self, _ = NewChequebook(path, common.Address{}, prvKey, backend)
165168

166169
err = json.Unmarshal(data, self)
@@ -170,8 +173,7 @@ func LoadChequebook(path string, prvKey *ecdsa.PrivateKey, backend Backend, chec
170173
if checkBalance {
171174
self.setBalanceFromBlockChain()
172175
}
173-
174-
log.Trace(fmt.Sprintf("loaded chequebook (%s, owner: %v, balance: %v) initialised from %v", self.contractAddr.Hex(), self.owner.Hex(), self.balance, path))
176+
log.Trace("Loaded chequebook from disk", "path", path)
175177

176178
return
177179
}
@@ -226,7 +228,7 @@ func (self *Chequebook) Save() (err error) {
226228
if err != nil {
227229
return err
228230
}
229-
log.Trace(fmt.Sprintf("saving chequebook (%s) to %v", self.contractAddr.Hex(), self.path))
231+
self.log.Trace("Saving chequebook to disk", self.path)
230232

231233
return ioutil.WriteFile(self.path, data, os.ModePerm)
232234
}
@@ -339,12 +341,12 @@ func (self *Chequebook) deposit(amount *big.Int) (string, error) {
339341
chbookRaw := &contract.ChequebookRaw{Contract: self.contract}
340342
tx, err := chbookRaw.Transfer(depositTransactor)
341343
if err != nil {
342-
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))
344+
self.log.Warn("Failed to fund chequebook", "amount", amount, "balance", self.balance, "target", self.buffer, "err", err)
343345
return "", err
344346
}
345347
// assume that transaction is actually successful, we add the amount to balance right away
346348
self.balance.Add(self.balance, amount)
347-
log.Trace(fmt.Sprintf("deposited %d wei to chequebook (%s, balance: %v, target: %v)", amount, self.contractAddr.Hex(), self.balance, self.buffer))
349+
self.log.Trace("Deposited funds to chequebook", "amount", amount, "balance", self.balance, "target", self.buffer)
348350
return tx.Hash().Hex(), nil
349351
}
350352

@@ -440,6 +442,7 @@ type Inbox struct {
440442
maxUncashed *big.Int // threshold that triggers autocashing
441443
cashed *big.Int // cumulative amount cashed
442444
cheque *Cheque // last cheque, nil if none yet received
445+
log log.Logger // contextual logger with the contrac address embedded
443446
}
444447

445448
// 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
467470
signer: signer,
468471
session: session,
469472
cashed: new(big.Int).Set(common.Big0),
473+
log: log.New("contract", contractAddr),
470474
}
471-
log.Trace(fmt.Sprintf("initialised inbox (%s -> %s) expected signer: %x", self.contract.Hex(), self.beneficiary.Hex(), crypto.FromECDSAPub(signer)))
475+
self.log.Trace("New chequebook inbox initialized", "beneficiary", self.beneficiary, "signer", hexutil.Bytes(crypto.FromECDSAPub(signer)))
472476
return
473477
}
474478

@@ -490,7 +494,7 @@ func (self *Inbox) Stop() {
490494
func (self *Inbox) Cash() (txhash string, err error) {
491495
if self.cheque != nil {
492496
txhash, err = self.cheque.Cash(self.session)
493-
log.Trace(fmt.Sprintf("cashing cheque (total: %v) on chequebook (%s) sending to %v", self.cheque.Amount, self.contract.Hex(), self.beneficiary.Hex()))
497+
self.log.Trace("Cashing in chequebook cheque", "amount", self.cheque.Amount, "beneficiary", self.beneficiary)
494498
self.cashed = self.cheque.Amount
495499
}
496500
return
@@ -574,15 +578,15 @@ func (self *Inbox) Receive(promise swap.Promise) (*big.Int, error) {
574578
self.Cash()
575579
}
576580
}
577-
log.Trace(fmt.Sprintf("received cheque of %v wei in inbox (%s, uncashed: %v)", amount, self.contract.Hex(), uncashed))
581+
self.log.Trace("Received cheque in chequebook inbox", "amount", amount, "uncashed", uncashed)
578582
}
579583

580584
return amount, err
581585
}
582586

583587
// Verify verifies cheque for signer, contract, beneficiary, amount, valid signature.
584588
func (self *Cheque) Verify(signerKey *ecdsa.PublicKey, contract, beneficiary common.Address, sum *big.Int) (*big.Int, error) {
585-
log.Trace(fmt.Sprintf("verify cheque: %v - sum: %v", self, sum))
589+
log.Trace("Verifying chequebook cheque", "cheque", self, "sum", sum)
586590
if sum == nil {
587591
return nil, fmt.Errorf("invalid amount")
588592
}

‎contracts/release/release.go‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ func (r *ReleaseService) checker() {
127127
version, err := r.oracle.CurrentVersion(opts)
128128
if err != nil {
129129
if err == bind.ErrNoCode {
130-
log.Debug(fmt.Sprintf("Release oracle not found at %x", r.config.Oracle))
130+
log.Debug("Release oracle not found", "contract", r.config.Oracle)
131131
continue
132132
}
133-
log.Error(fmt.Sprintf("Failed to retrieve current release: %v", err))
133+
log.Error("Failed to retrieve current release", "err", err)
134134
continue
135135
}
136136
// Version was successfully retrieved, notify if newer than ours
@@ -143,13 +143,14 @@ func (r *ReleaseService) checker() {
143143
howtofix := fmt.Sprintf("Please check https://github.com/ethereum/go-ethereum/releases for new releases")
144144
separator := strings.Repeat("-", len(warning))
145145

146-
log.Warn(fmt.Sprint(separator))
147-
log.Warn(fmt.Sprint(warning))
148-
log.Warn(fmt.Sprint(howtofix))
149-
log.Warn(fmt.Sprint(separator))
146+
log.Warn(separator)
147+
log.Warn(warning)
148+
log.Warn(howtofix)
149+
log.Warn(separator)
150150
} else {
151-
log.Debug(fmt.Sprintf("Client v%d.%d.%d-%x seems up to date with upstream v%d.%d.%d-%x",
152-
r.config.Major, r.config.Minor, r.config.Patch, r.config.Commit[:4], version.Major, version.Minor, version.Patch, version.Commit[:4]))
151+
log.Debug("Client seems up to date with upstream",
152+
"local", fmt.Sprintf("v%d.%d.%d-%x", r.config.Major, r.config.Minor, r.config.Patch, r.config.Commit[:4]),
153+
"upstream", fmt.Sprintf("v%d.%d.%d-%x", version.Major, version.Minor, version.Patch, version.Commit[:4]))
153154
}
154155

155156
// If termination was requested, return

‎core/block_validator.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (v *BlockValidator) VerifyUncles(block, parent *types.Block) error {
170170
for h := range ancestors {
171171
branch += fmt.Sprintf(" O - %x\n |\n", h)
172172
}
173-
log.Info(fmt.Sprint(branch))
173+
log.Warn(branch)
174174
return UncleError("uncle[%d](%x) is ancestor", i, hash[:4])
175175
}
176176

0 commit comments

Comments
 (0)