diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-02-22 22:58:00 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-02-23 18:16:46 +0800 |
commit | 23a5d64fd059bb8bdf02781608a15b8b1bdbdfd2 (patch) | |
tree | 143cd04a9fe002b25c146e7c0b5aacfbe62092eb /accounts | |
parent | 61e6bb12478740d614c8effd330f881f962b7b84 (diff) | |
download | go-tangerine-23a5d64fd059bb8bdf02781608a15b8b1bdbdfd2.tar.gz go-tangerine-23a5d64fd059bb8bdf02781608a15b8b1bdbdfd2.tar.zst go-tangerine-23a5d64fd059bb8bdf02781608a15b8b1bdbdfd2.zip |
accounts, cmd: port packages over to the new logging system
Diffstat (limited to 'accounts')
-rw-r--r-- | accounts/abi/bind/util.go | 9 | ||||
-rw-r--r-- | accounts/keystore/account_cache.go | 14 | ||||
-rw-r--r-- | accounts/keystore/watch.go | 12 | ||||
-rw-r--r-- | accounts/usbwallet/ledger_hub.go | 3 | ||||
-rw-r--r-- | accounts/usbwallet/ledger_wallet.go | 27 |
5 files changed, 36 insertions, 29 deletions
diff --git a/accounts/abi/bind/util.go b/accounts/abi/bind/util.go index 88234688e..ca79694ef 100644 --- a/accounts/abi/bind/util.go +++ b/accounts/abi/bind/util.go @@ -29,18 +29,19 @@ import ( // WaitMined waits for tx to be mined on the blockchain. // It stops waiting when the context is canceled. func WaitMined(ctx context.Context, b DeployBackend, tx *types.Transaction) (*types.Receipt, error) { - queryTicker := time.NewTicker(1 * time.Second) + queryTicker := time.NewTicker(time.Second) defer queryTicker.Stop() - loghash := tx.Hash().Hex()[:8] + + logger := log.New("hash", tx.Hash().Hex()[:8]) for { receipt, err := b.TransactionReceipt(ctx, tx.Hash()) if receipt != nil { return receipt, nil } if err != nil { - log.Trace(fmt.Sprintf("tx %x error: %v", loghash, err)) + logger.Trace("Receipt retrieval failed", "error", err) } else { - log.Trace(fmt.Sprintf("tx %x not yet mined...", loghash)) + logger.Trace("Transaction not yet mined") } // Wait for the next round. select { diff --git a/accounts/keystore/account_cache.go b/accounts/keystore/account_cache.go index 11100ebc1..866f8ae7b 100644 --- a/accounts/keystore/account_cache.go +++ b/accounts/keystore/account_cache.go @@ -210,7 +210,7 @@ func (ac *accountCache) close() { func (ac *accountCache) reload() { accounts, err := ac.scan() if err != nil { - log.Debug(fmt.Sprintf("can't load keys: %v", err)) + log.Debug("Failed to reload keystore contents", "error", err) } ac.all = accounts sort.Sort(ac.all) @@ -224,7 +224,7 @@ func (ac *accountCache) reload() { case ac.notify <- struct{}{}: default: } - log.Debug(fmt.Sprintf("reloaded keys, cache has %d accounts", len(ac.all))) + log.Debug("Reloaded keystore contents", "accounts", len(ac.all)) } func (ac *accountCache) scan() ([]accounts.Account, error) { @@ -243,12 +243,14 @@ func (ac *accountCache) scan() ([]accounts.Account, error) { for _, fi := range files { path := filepath.Join(ac.keydir, fi.Name()) if skipKeyFile(fi) { - log.Trace(fmt.Sprintf("ignoring file %s", path)) + log.Trace("Ignoring file on account scan", "path", path) continue } + logger := log.New("path", path) + fd, err := os.Open(path) if err != nil { - log.Trace(fmt.Sprint(err)) + logger.Trace("Failed to open keystore file", "error", err) continue } buf.Reset(fd) @@ -258,9 +260,9 @@ func (ac *accountCache) scan() ([]accounts.Account, error) { addr := common.HexToAddress(keyJSON.Address) switch { case err != nil: - log.Debug(fmt.Sprintf("can't decode key %s: %v", path, err)) + logger.Debug("Failed to decode keystore key", "error", err) case (addr == common.Address{}): - log.Debug(fmt.Sprintf("can't decode key %s: missing or zero address", path)) + logger.Debug("Failed to decode keystore key", "error", "missing or zero address") default: addrs = append(addrs, accounts.Account{Address: addr, URL: accounts.URL{Scheme: KeyStoreScheme, Path: path}}) } diff --git a/accounts/keystore/watch.go b/accounts/keystore/watch.go index ff95a7cdc..ae97805be 100644 --- a/accounts/keystore/watch.go +++ b/accounts/keystore/watch.go @@ -19,7 +19,6 @@ package keystore import ( - "fmt" "time" "github.com/ethereum/go-ethereum/log" @@ -64,15 +63,16 @@ func (w *watcher) loop() { w.starting = false w.ac.mu.Unlock() }() + logger := log.New("path", w.ac.keydir) - err := notify.Watch(w.ac.keydir, w.ev, notify.All) - if err != nil { - log.Trace(fmt.Sprintf("can't watch %s: %v", w.ac.keydir, err)) + if err := notify.Watch(w.ac.keydir, w.ev, notify.All); err != nil { + logger.Trace("Failed to watch keystore folder", "error", err) return } defer notify.Stop(w.ev) - log.Trace(fmt.Sprintf("now watching %s", w.ac.keydir)) - defer log.Trace(fmt.Sprintf("no longer watching %s", w.ac.keydir)) + + logger.Trace("Started watching keystore folder") + defer logger.Trace("Stopped watching keystore folder") w.ac.mu.Lock() w.running = true diff --git a/accounts/usbwallet/ledger_hub.go b/accounts/usbwallet/ledger_hub.go index 70396d314..d1aeed748 100644 --- a/accounts/usbwallet/ledger_hub.go +++ b/accounts/usbwallet/ledger_hub.go @@ -27,6 +27,7 @@ import ( "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/event" + "github.com/ethereum/go-ethereum/log" "github.com/karalabe/hid" ) @@ -120,7 +121,7 @@ func (hub *LedgerHub) refreshWallets() { } // If there are no more wallets or the device is before the next, wrap new wallet if len(hub.wallets) == 0 || hub.wallets[0].URL().Cmp(url) > 0 { - wallet := &ledgerWallet{url: &url, info: ledger} + wallet := &ledgerWallet{url: &url, info: ledger, logger: log.New("url", url)} events = append(events, accounts.WalletEvent{Wallet: wallet, Arrive: true}) wallets = append(wallets, wallet) diff --git a/accounts/usbwallet/ledger_wallet.go b/accounts/usbwallet/ledger_wallet.go index 0dc53daf5..6086660f9 100644 --- a/accounts/usbwallet/ledger_wallet.go +++ b/accounts/usbwallet/ledger_wallet.go @@ -33,6 +33,7 @@ import ( ethereum "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" @@ -122,6 +123,8 @@ type ledgerWallet struct { // must only ever hold a *read* lock to stateLock. commsLock chan struct{} // Mutex (buf=1) for the USB comms without keeping the state locked stateLock sync.RWMutex // Protects read and write access to the wallet struct fields + + logger log.Logger // Contextual logger to tag the ledger with its id } // URL implements accounts.Wallet, returning the URL of the Ledger device. @@ -219,8 +222,8 @@ func (w *ledgerWallet) Open(passphrase string) error { // - libusb on Windows doesn't support hotplug, so we can't detect USB unplugs // - communication timeout on the Ledger requires a device power cycle to fix func (w *ledgerWallet) heartbeat() { - log.Debug(fmt.Sprintf("%s health-check started", w.url.String())) - defer log.Debug(fmt.Sprintf("%s health-check stopped", w.url.String())) + w.logger.Debug("Ledger health-check started") + defer w.logger.Debug("Ledger health-check stopped") // Execute heartbeat checks until termination or error var ( @@ -259,7 +262,7 @@ func (w *ledgerWallet) heartbeat() { } // In case of error, wait for termination if err != nil { - log.Debug(fmt.Sprintf("%s health-check failed: %v", w.url.String(), err)) + w.logger.Debug("Ledger health-check failed", "error", err) errc = <-w.healthQuit } errc <- err @@ -347,8 +350,8 @@ func (w *ledgerWallet) Accounts() []accounts.Account { // selfDerive is an account derivation loop that upon request attempts to find // new non-zero accounts. func (w *ledgerWallet) selfDerive() { - log.Debug(fmt.Sprintf("%s self-derivation started", w.url.String())) - defer log.Debug(fmt.Sprintf("%s self-derivation stopped", w.url.String())) + w.logger.Debug("Ledger self-derivation started") + defer w.logger.Debug("Ledger self-derivation stopped") // Execute self-derivations until termination or error var ( @@ -393,7 +396,7 @@ func (w *ledgerWallet) selfDerive() { // Retrieve the next derived Ethereum account if nextAddr == (common.Address{}) { if nextAddr, err = w.ledgerDerive(nextPath); err != nil { - log.Warn(fmt.Sprintf("%s self-derivation failed: %v", w.url.String(), err)) + w.logger.Warn("Ledger account derivation failed", "error", err) break } } @@ -404,12 +407,12 @@ func (w *ledgerWallet) selfDerive() { ) balance, err = w.deriveChain.BalanceAt(context, nextAddr, nil) if err != nil { - log.Warn(fmt.Sprintf("%s self-derivation balance retrieval failed: %v", w.url.String(), err)) + w.logger.Warn("Ledger balance retrieval failed", "error", err) break } nonce, err = w.deriveChain.NonceAt(context, nextAddr, nil) if err != nil { - log.Warn(fmt.Sprintf("%s self-derivation nonce retrieval failed: %v", w.url.String(), err)) + w.logger.Warn("Ledger nonce retrieval failed", "error", err) break } // If the next account is empty, stop self-derivation, but add it nonetheless @@ -429,7 +432,7 @@ func (w *ledgerWallet) selfDerive() { // Display a log message to the user for new (or previously empty accounts) if _, known := w.paths[nextAddr]; !known || (!empty && nextAddr == w.deriveNextAddr) { - log.Info(fmt.Sprintf("%s discovered %s (balance %22v, nonce %4d) at %s", w.url.String(), nextAddr.Hex(), balance, nonce, path)) + w.logger.Info("Ledger discovered new account", "address", nextAddr.Hex(), "path", path, "balance", balance, "nonce", nonce) } // Fetch the next potential account if !empty { @@ -468,7 +471,7 @@ func (w *ledgerWallet) selfDerive() { } // In case of error, wait for termination if err != nil { - log.Debug(fmt.Sprintf("%s self-derivation failed: %s", w.url.String(), err)) + w.logger.Debug("Ledger self-derivation failed", "error", err) errc = <-w.deriveQuit } errc <- err @@ -848,7 +851,7 @@ func (w *ledgerWallet) ledgerExchange(opcode ledgerOpcode, p1 ledgerParam1, p2 l apdu = nil } // Send over to the device - log.Trace("", "msg", log.Lazy{Fn: func() string { return fmt.Sprintf("-> %s: %x", w.device.Path, chunk) }}) + w.logger.Trace("Data chunk sent to the Ledger", "chunk", hexutil.Bytes(chunk)) if _, err := w.device.Write(chunk); err != nil { return nil, err } @@ -861,7 +864,7 @@ func (w *ledgerWallet) ledgerExchange(opcode ledgerOpcode, p1 ledgerParam1, p2 l if _, err := io.ReadFull(w.device, chunk); err != nil { return nil, err } - log.Trace("", "msg", log.Lazy{Fn: func() string { return fmt.Sprintf("<- %s: %x", w.device.Path, chunk) }}) + w.logger.Trace("Data chunk received from the Ledger", "chunk", hexutil.Bytes(chunk)) // Make sure the transport header matches if chunk[0] != 0x01 || chunk[1] != 0x01 || chunk[2] != 0x05 { |