Skip to content

Commit

Permalink
all: blidly swap out glog to our log15, logs need rework
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe committed Feb 23, 2017
1 parent 47af53f commit d4fd06c
Show file tree
Hide file tree
Showing 147 changed files with 1,546 additions and 3,693 deletions.
7 changes: 3 additions & 4 deletions accounts/abi/bind/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/log"
"golang.org/x/net/context"
)

Expand All @@ -39,9 +38,9 @@ func WaitMined(ctx context.Context, b DeployBackend, tx *types.Transaction) (*ty
return receipt, nil
}
if err != nil {
glog.V(logger.Detail).Infof("tx %x error: %v", loghash, err)
log.Trace(fmt.Sprintf("tx %x error: %v", loghash, err))
} else {
glog.V(logger.Detail).Infof("tx %x not yet mined...", loghash)
log.Trace(fmt.Sprintf("tx %x not yet mined...", loghash))
}
// Wait for the next round.
select {
Expand Down
17 changes: 8 additions & 9 deletions accounts/keystore/account_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ import (

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/log"
)

// Minimum amount of time between cache reloads. This limit applies if the platform does
Expand Down Expand Up @@ -210,8 +209,8 @@ func (ac *accountCache) close() {
// Callers must hold ac.mu.
func (ac *accountCache) reload() {
accounts, err := ac.scan()
if err != nil && glog.V(logger.Debug) {
glog.Errorf("can't load keys: %v", err)
if err != nil {
log.Debug(fmt.Sprintf("can't load keys: %v", err))
}
ac.all = accounts
sort.Sort(ac.all)
Expand All @@ -225,7 +224,7 @@ func (ac *accountCache) reload() {
case ac.notify <- struct{}{}:
default:
}
glog.V(logger.Debug).Infof("reloaded keys, cache has %d accounts", len(ac.all))
log.Debug(fmt.Sprintf("reloaded keys, cache has %d accounts", len(ac.all)))
}

func (ac *accountCache) scan() ([]accounts.Account, error) {
Expand All @@ -244,12 +243,12 @@ func (ac *accountCache) scan() ([]accounts.Account, error) {
for _, fi := range files {
path := filepath.Join(ac.keydir, fi.Name())
if skipKeyFile(fi) {
glog.V(logger.Detail).Infof("ignoring file %s", path)
log.Trace(fmt.Sprintf("ignoring file %s", path))
continue
}
fd, err := os.Open(path)
if err != nil {
glog.V(logger.Detail).Infoln(err)
log.Trace(fmt.Sprint(err))
continue
}
buf.Reset(fd)
Expand All @@ -259,9 +258,9 @@ func (ac *accountCache) scan() ([]accounts.Account, error) {
addr := common.HexToAddress(keyJSON.Address)
switch {
case err != nil:
glog.V(logger.Debug).Infof("can't decode key %s: %v", path, err)
log.Debug(fmt.Sprintf("can't decode key %s: %v", path, err))
case (addr == common.Address{}):
glog.V(logger.Debug).Infof("can't decode key %s: missing or zero address", path)
log.Debug(fmt.Sprintf("can't decode key %s: missing or zero address", path))
default:
addrs = append(addrs, accounts.Account{Address: addr, URL: accounts.URL{Scheme: KeyStoreScheme, Path: path}})
}
Expand Down
10 changes: 5 additions & 5 deletions accounts/keystore/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
package keystore

import (
"fmt"
"time"

"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/log"
"github.com/rjeczalik/notify"
)

Expand Down Expand Up @@ -67,12 +67,12 @@ func (w *watcher) loop() {

err := notify.Watch(w.ac.keydir, w.ev, notify.All)
if err != nil {
glog.V(logger.Detail).Infof("can't watch %s: %v", w.ac.keydir, err)
log.Trace(fmt.Sprintf("can't watch %s: %v", w.ac.keydir, err))
return
}
defer notify.Stop(w.ev)
glog.V(logger.Detail).Infof("now watching %s", w.ac.keydir)
defer glog.V(logger.Detail).Infof("no longer watching %s", w.ac.keydir)
log.Trace(fmt.Sprintf("now watching %s", w.ac.keydir))
defer log.Trace(fmt.Sprintf("no longer watching %s", w.ac.keydir))

w.ac.mu.Lock()
w.running = true
Expand Down
32 changes: 14 additions & 18 deletions accounts/usbwallet/ledger_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ import (
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"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"
"github.com/karalabe/hid"
"golang.org/x/net/context"
Expand Down Expand Up @@ -220,8 +219,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() {
glog.V(logger.Debug).Infof("%s health-check started", w.url.String())
defer glog.V(logger.Debug).Infof("%s health-check stopped", w.url.String())
log.Debug(fmt.Sprintf("%s health-check started", w.url.String()))
defer log.Debug(fmt.Sprintf("%s health-check stopped", w.url.String()))

// Execute heartbeat checks until termination or error
var (
Expand Down Expand Up @@ -260,7 +259,7 @@ func (w *ledgerWallet) heartbeat() {
}
// In case of error, wait for termination
if err != nil {
glog.V(logger.Debug).Infof("%s health-check failed: %v", w.url.String(), err)
log.Debug(fmt.Sprintf("%s health-check failed: %v", w.url.String(), err))
errc = <-w.healthQuit
}
errc <- err
Expand Down Expand Up @@ -348,8 +347,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() {
glog.V(logger.Debug).Infof("%s self-derivation started", w.url.String())
defer glog.V(logger.Debug).Infof("%s self-derivation stopped", w.url.String())
log.Debug(fmt.Sprintf("%s self-derivation started", w.url.String()))
defer log.Debug(fmt.Sprintf("%s self-derivation stopped", w.url.String()))

// Execute self-derivations until termination or error
var (
Expand Down Expand Up @@ -394,7 +393,7 @@ func (w *ledgerWallet) selfDerive() {
// Retrieve the next derived Ethereum account
if nextAddr == (common.Address{}) {
if nextAddr, err = w.ledgerDerive(nextPath); err != nil {
glog.V(logger.Warn).Infof("%s self-derivation failed: %v", w.url.String(), err)
log.Warn(fmt.Sprintf("%s self-derivation failed: %v", w.url.String(), err))
break
}
}
Expand All @@ -405,12 +404,12 @@ func (w *ledgerWallet) selfDerive() {
)
balance, err = w.deriveChain.BalanceAt(context, nextAddr, nil)
if err != nil {
glog.V(logger.Warn).Infof("%s self-derivation balance retrieval failed: %v", w.url.String(), err)
log.Warn(fmt.Sprintf("%s self-derivation balance retrieval failed: %v", w.url.String(), err))
break
}
nonce, err = w.deriveChain.NonceAt(context, nextAddr, nil)
if err != nil {
glog.V(logger.Warn).Infof("%s self-derivation nonce retrieval failed: %v", w.url.String(), err)
log.Warn(fmt.Sprintf("%s self-derivation nonce retrieval failed: %v", w.url.String(), err))
break
}
// If the next account is empty, stop self-derivation, but add it nonetheless
Expand All @@ -430,7 +429,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) {
glog.V(logger.Info).Infof("%s discovered %s (balance %22v, nonce %4d) at %s", w.url.String(), nextAddr.Hex(), balance, nonce, path)
log.Info(fmt.Sprintf("%s discovered %s (balance %22v, nonce %4d) at %s", w.url.String(), nextAddr.Hex(), balance, nonce, path))
}
// Fetch the next potential account
if !empty {
Expand Down Expand Up @@ -469,7 +468,7 @@ func (w *ledgerWallet) selfDerive() {
}
// In case of error, wait for termination
if err != nil {
glog.V(logger.Debug).Infof("%s self-derivation failed: %s", w.url.String(), err)
log.Debug(fmt.Sprintf("%s self-derivation failed: %s", w.url.String(), err))
errc = <-w.deriveQuit
}
errc <- err
Expand Down Expand Up @@ -849,9 +848,7 @@ func (w *ledgerWallet) ledgerExchange(opcode ledgerOpcode, p1 ledgerParam1, p2 l
apdu = nil
}
// Send over to the device
if glog.V(logger.Detail) {
glog.Infof("-> %s: %x", w.device.Path, chunk)
}
log.Trace("", "msg", log.Lazy{Fn: func() string { return fmt.Sprintf("-> %s: %x", w.device.Path, chunk) }})
if _, err := w.device.Write(chunk); err != nil {
return nil, err
}
Expand All @@ -864,9 +861,8 @@ func (w *ledgerWallet) ledgerExchange(opcode ledgerOpcode, p1 ledgerParam1, p2 l
if _, err := io.ReadFull(w.device, chunk); err != nil {
return nil, err
}
if glog.V(logger.Detail) {
glog.Infof("<- %s: %x", w.device.Path, chunk)
}
log.Trace("", "msg", log.Lazy{Fn: func() string { return fmt.Sprintf("<- %s: %x", w.device.Path, chunk) }})

// Make sure the transport header matches
if chunk[0] != 0x01 || chunk[1] != 0x01 || chunk[2] != 0x05 {
return nil, errReplyInvalidHeader
Expand Down
2 changes: 1 addition & 1 deletion build/update-license.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
// boring stuff
"vendor/", "tests/files/", "build/",
// don't relicense vendored sources
"crypto/sha3/", "crypto/ecies/", "logger/glog/",
"crypto/sha3/", "crypto/ecies/", "log/",
"crypto/secp256k1/curve.go",
// don't license generated files
"contracts/chequebook/contract/",
Expand Down
33 changes: 18 additions & 15 deletions cmd/bootnode/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ import (
"fmt"
"os"

"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/discv5"
"github.com/ethereum/go-ethereum/p2p/nat"
Expand All @@ -42,39 +41,43 @@ func main() {
natdesc = flag.String("nat", "none", "port mapping mechanism (any|none|upnp|pmp|extip:<IP>)")
netrestrict = flag.String("netrestrict", "", "restrict network communication to the given IP networks (CIDR masks)")
runv5 = flag.Bool("v5", false, "run a v5 topic discovery bootnode")
verbosity = flag.Int("verbosity", int(log.LvlInfo), "log verbosity (0-9)")
vmodule = flag.String("vmodule", "", "log verbosity pattern")

nodeKey *ecdsa.PrivateKey
err error
)
flag.Var(glog.GetVerbosity(), "verbosity", "log verbosity (0-9)")
flag.Var(glog.GetVModule(), "vmodule", "log verbosity pattern")
glog.SetToStderr(true)
flag.Parse()

glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.TerminalFormat()))
glogger.Verbosity(log.Lvl(*verbosity))
glogger.Vmodule(*vmodule)
log.Root().SetHandler(glogger)

natm, err := nat.Parse(*natdesc)
if err != nil {
utils.Fatalf("-nat: %v", err)
log.Crit(fmt.Sprintf("-nat: %v", err))
}
switch {
case *genKey != "":
nodeKey, err = crypto.GenerateKey()
if err != nil {
utils.Fatalf("could not generate key: %v", err)
log.Crit(fmt.Sprintf("could not generate key: %v", err))
}
if err = crypto.SaveECDSA(*genKey, nodeKey); err != nil {
utils.Fatalf("%v", err)
log.Crit(fmt.Sprintf("%v", err))
}
case *nodeKeyFile == "" && *nodeKeyHex == "":
utils.Fatalf("Use -nodekey or -nodekeyhex to specify a private key")
log.Crit(fmt.Sprintf("Use -nodekey or -nodekeyhex to specify a private key"))
case *nodeKeyFile != "" && *nodeKeyHex != "":
utils.Fatalf("Options -nodekey and -nodekeyhex are mutually exclusive")
log.Crit(fmt.Sprintf("Options -nodekey and -nodekeyhex are mutually exclusive"))
case *nodeKeyFile != "":
if nodeKey, err = crypto.LoadECDSA(*nodeKeyFile); err != nil {
utils.Fatalf("-nodekey: %v", err)
log.Crit(fmt.Sprintf("-nodekey: %v", err))
}
case *nodeKeyHex != "":
if nodeKey, err = crypto.HexToECDSA(*nodeKeyHex); err != nil {
utils.Fatalf("-nodekeyhex: %v", err)
log.Crit(fmt.Sprintf("-nodekeyhex: %v", err))
}
}

Expand All @@ -87,17 +90,17 @@ func main() {
if *netrestrict != "" {
restrictList, err = netutil.ParseNetlist(*netrestrict)
if err != nil {
utils.Fatalf("-netrestrict: %v", err)
log.Crit(fmt.Sprintf("-netrestrict: %v", err))
}
}

if *runv5 {
if _, err := discv5.ListenUDP(nodeKey, *listenAddr, natm, "", restrictList); err != nil {
utils.Fatalf("%v", err)
log.Crit(fmt.Sprintf("%v", err))
}
} else {
if _, err := discover.ListenUDP(nodeKey, *listenAddr, natm, "", restrictList); err != nil {
utils.Fatalf("%v", err)
log.Crit(fmt.Sprintf("%v", err))
}
}

Expand Down
Loading

0 comments on commit d4fd06c

Please sign in to comment.