aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/utils
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-02-22 20:10:07 +0800
committerPéter Szilágyi <peterke@gmail.com>2017-02-23 18:16:44 +0800
commitd4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851 (patch)
tree17c93170551d3eeabe2935de1765f157007f0dc2 /cmd/utils
parent47af53f9aaf9aa7b12cd976eb150ccf3d64da6fd (diff)
downloadgo-tangerine-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.gz
go-tangerine-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.zst
go-tangerine-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.zip
all: blidly swap out glog to our log15, logs need rework
Diffstat (limited to 'cmd/utils')
-rw-r--r--cmd/utils/cmd.go25
-rw-r--r--cmd/utils/flags.go49
2 files changed, 36 insertions, 38 deletions
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index 8666f3775..e288f8bd2 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -31,8 +31,7 @@ import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/internal/debug"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/rlp"
)
@@ -72,19 +71,19 @@ func Fatalf(format string, args ...interface{}) {
func StartNode(stack *node.Node) {
if err := stack.Start(); err != nil {
- Fatalf("Error starting protocol stack: %v", err)
+ log.Crit(fmt.Sprintf("Error starting protocol stack: %v", err))
}
go func() {
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, os.Interrupt)
defer signal.Stop(sigc)
<-sigc
- glog.V(logger.Info).Infoln("Got interrupt, shutting down...")
+ log.Info(fmt.Sprint("Got interrupt, shutting down..."))
go stack.Stop()
for i := 10; i > 0; i-- {
<-sigc
if i > 1 {
- glog.V(logger.Info).Infof("Already shutting down, interrupt %d more times for panic.", i-1)
+ log.Info(fmt.Sprintf("Already shutting down, interrupt %d more times for panic.", i-1))
}
}
debug.Exit() // ensure trace and CPU profile data is flushed.
@@ -115,7 +114,7 @@ func ImportChain(chain *core.BlockChain, fn string) error {
defer close(interrupt)
go func() {
if _, ok := <-interrupt; ok {
- glog.Info("caught interrupt during import, will stop at next batch")
+ log.Info(fmt.Sprint("caught interrupt during import, will stop at next batch"))
}
close(stop)
}()
@@ -128,7 +127,7 @@ func ImportChain(chain *core.BlockChain, fn string) error {
}
}
- glog.Infoln("Importing blockchain ", fn)
+ log.Info(fmt.Sprint("Importing blockchain ", fn))
fh, err := os.Open(fn)
if err != nil {
return err
@@ -176,8 +175,8 @@ func ImportChain(chain *core.BlockChain, fn string) error {
return fmt.Errorf("interrupted")
}
if hasAllBlocks(chain, blocks[:i]) {
- glog.Infof("skipping batch %d, all blocks present [%x / %x]",
- batch, blocks[0].Hash().Bytes()[:4], blocks[i-1].Hash().Bytes()[:4])
+ log.Info(fmt.Sprintf("skipping batch %d, all blocks present [%x / %x]",
+ batch, blocks[0].Hash().Bytes()[:4], blocks[i-1].Hash().Bytes()[:4]))
continue
}
@@ -198,7 +197,7 @@ func hasAllBlocks(chain *core.BlockChain, bs []*types.Block) bool {
}
func ExportChain(blockchain *core.BlockChain, fn string) error {
- glog.Infoln("Exporting blockchain to ", fn)
+ log.Info(fmt.Sprint("Exporting blockchain to ", fn))
fh, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm)
if err != nil {
return err
@@ -214,13 +213,13 @@ func ExportChain(blockchain *core.BlockChain, fn string) error {
if err := blockchain.Export(writer); err != nil {
return err
}
- glog.Infoln("Exported blockchain to ", fn)
+ log.Info(fmt.Sprint("Exported blockchain to ", fn))
return nil
}
func ExportAppendChain(blockchain *core.BlockChain, fn string, first uint64, last uint64) error {
- glog.Infoln("Exporting blockchain to ", fn)
+ log.Info(fmt.Sprint("Exporting blockchain to ", fn))
// TODO verify mode perms
fh, err := os.OpenFile(fn, os.O_CREATE|os.O_APPEND|os.O_WRONLY, os.ModePerm)
if err != nil {
@@ -237,6 +236,6 @@ func ExportAppendChain(blockchain *core.BlockChain, fn string, first uint64, las
if err := blockchain.ExportN(writer, first, last); err != nil {
return err
}
- glog.Infoln("Exported blockchain to ", fn)
+ log.Info(fmt.Sprint("Exported blockchain to ", fn))
return nil
}
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 92eb05e32..55713c15c 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -41,8 +41,7 @@ import (
"github.com/ethereum/go-ethereum/ethstats"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/les"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p/discover"
@@ -426,7 +425,7 @@ func MakeDataDir(ctx *cli.Context) string {
}
return path
}
- Fatalf("Cannot determine default data directory, please set manually (--datadir)")
+ log.Crit(fmt.Sprintf("Cannot determine default data directory, please set manually (--datadir)"))
return ""
}
@@ -452,16 +451,16 @@ func MakeNodeKey(ctx *cli.Context) *ecdsa.PrivateKey {
)
switch {
case file != "" && hex != "":
- Fatalf("Options %q and %q are mutually exclusive", NodeKeyFileFlag.Name, NodeKeyHexFlag.Name)
+ log.Crit(fmt.Sprintf("Options %q and %q are mutually exclusive", NodeKeyFileFlag.Name, NodeKeyHexFlag.Name))
case file != "":
if key, err = crypto.LoadECDSA(file); err != nil {
- Fatalf("Option %q: %v", NodeKeyFileFlag.Name, err)
+ log.Crit(fmt.Sprintf("Option %q: %v", NodeKeyFileFlag.Name, err))
}
case hex != "":
if key, err = crypto.HexToECDSA(hex); err != nil {
- Fatalf("Option %q: %v", NodeKeyHexFlag.Name, err)
+ log.Crit(fmt.Sprintf("Option %q: %v", NodeKeyHexFlag.Name, err))
}
}
return key
@@ -493,7 +492,7 @@ func MakeBootstrapNodes(ctx *cli.Context) []*discover.Node {
for _, url := range urls {
node, err := discover.ParseNode(url)
if err != nil {
- glog.V(logger.Error).Infof("Bootstrap URL %s: %v\n", url, err)
+ log.Error(fmt.Sprintf("Bootstrap URL %s: %v\n", url, err))
continue
}
bootnodes = append(bootnodes, node)
@@ -513,7 +512,7 @@ func MakeBootstrapNodesV5(ctx *cli.Context) []*discv5.Node {
for _, url := range urls {
node, err := discv5.ParseNode(url)
if err != nil {
- glog.V(logger.Error).Infof("Bootstrap URL %s: %v\n", url, err)
+ log.Error(fmt.Sprintf("Bootstrap URL %s: %v\n", url, err))
continue
}
bootnodes = append(bootnodes, node)
@@ -537,7 +536,7 @@ func MakeDiscoveryV5Address(ctx *cli.Context) string {
func MakeNAT(ctx *cli.Context) nat.Interface {
natif, err := nat.Parse(ctx.GlobalString(NATFlag.Name))
if err != nil {
- Fatalf("Option %s: %v", NATFlag.Name, err)
+ log.Crit(fmt.Sprintf("Option %s: %v", NATFlag.Name, err))
}
return natif
}
@@ -574,11 +573,11 @@ func MakeWSRpcHost(ctx *cli.Context) string {
// for Geth and returns half of the allowance to assign to the database.
func MakeDatabaseHandles() int {
if err := raiseFdLimit(2048); err != nil {
- Fatalf("Failed to raise file descriptor allowance: %v", err)
+ log.Crit(fmt.Sprintf("Failed to raise file descriptor allowance: %v", err))
}
limit, err := getFdLimit()
if err != nil {
- Fatalf("Failed to retrieve file descriptor allowance: %v", err)
+ log.Crit(fmt.Sprintf("Failed to retrieve file descriptor allowance: %v", err))
}
if limit > 2048 { // cap database file descriptors even if more is available
limit = 2048
@@ -610,7 +609,7 @@ func MakeAddress(ks *keystore.KeyStore, account string) (accounts.Account, error
func MakeEtherbase(ks *keystore.KeyStore, ctx *cli.Context) common.Address {
accounts := ks.Accounts()
if !ctx.GlobalIsSet(EtherbaseFlag.Name) && len(accounts) == 0 {
- glog.V(logger.Error).Infoln("WARNING: No etherbase set and no accounts found as default")
+ log.Error(fmt.Sprint("WARNING: No etherbase set and no accounts found as default"))
return common.Address{}
}
etherbase := ctx.GlobalString(EtherbaseFlag.Name)
@@ -620,7 +619,7 @@ func MakeEtherbase(ks *keystore.KeyStore, ctx *cli.Context) common.Address {
// If the specified etherbase is a valid address, return it
account, err := MakeAddress(ks, etherbase)
if err != nil {
- Fatalf("Option %q: %v", EtherbaseFlag.Name, err)
+ log.Crit(fmt.Sprintf("Option %q: %v", EtherbaseFlag.Name, err))
}
return account.Address
}
@@ -642,7 +641,7 @@ func MakePasswordList(ctx *cli.Context) []string {
}
text, err := ioutil.ReadFile(path)
if err != nil {
- Fatalf("Failed to read password file: %v", err)
+ log.Crit(fmt.Sprintf("Failed to read password file: %v", err))
}
lines := strings.Split(string(text), "\n")
// Sanitise DOS line endings.
@@ -701,14 +700,14 @@ func MakeNode(ctx *cli.Context, name, gitCommit string) *node.Node {
if netrestrict := ctx.GlobalString(NetrestrictFlag.Name); netrestrict != "" {
list, err := netutil.ParseNetlist(netrestrict)
if err != nil {
- Fatalf("Option %q: %v", NetrestrictFlag.Name, err)
+ log.Crit(fmt.Sprintf("Option %q: %v", NetrestrictFlag.Name, err))
}
config.NetRestrict = list
}
stack, err := node.New(config)
if err != nil {
- Fatalf("Failed to create the protocol stack: %v", err)
+ log.Crit(fmt.Sprintf("Failed to create the protocol stack: %v", err))
}
return stack
}
@@ -724,7 +723,7 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) {
}
}
if networks > 1 {
- Fatalf("The %v flags are mutually exclusive", netFlags)
+ log.Crit(fmt.Sprintf("The %v flags are mutually exclusive", netFlags))
}
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
@@ -778,7 +777,7 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) {
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
return les.New(ctx, ethConf)
}); err != nil {
- Fatalf("Failed to register the Ethereum light node service: %v", err)
+ log.Crit(fmt.Sprintf("Failed to register the Ethereum light node service: %v", err))
}
} else {
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
@@ -789,7 +788,7 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) {
}
return fullNode, err
}); err != nil {
- Fatalf("Failed to register the Ethereum full node service: %v", err)
+ log.Crit(fmt.Sprintf("Failed to register the Ethereum full node service: %v", err))
}
}
}
@@ -797,7 +796,7 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) {
// RegisterShhService configures Whisper and adds it to the given node.
func RegisterShhService(stack *node.Node) {
if err := stack.Register(func(*node.ServiceContext) (node.Service, error) { return whisper.New(), nil }); err != nil {
- Fatalf("Failed to register the Whisper service: %v", err)
+ log.Crit(fmt.Sprintf("Failed to register the Whisper service: %v", err))
}
}
@@ -814,7 +813,7 @@ func RegisterEthStatsService(stack *node.Node, url string) {
return ethstats.New(url, ethServ, lesServ)
}); err != nil {
- Fatalf("Failed to register the Ethereum Stats service: %v", err)
+ log.Crit(fmt.Sprintf("Failed to register the Ethereum Stats service: %v", err))
}
}
@@ -845,7 +844,7 @@ func MakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *params.ChainCon
case core.ChainConfigNotFoundErr:
// No configs found, use empty, will populate below
default:
- Fatalf("Could not make chain configuration: %v", err)
+ log.Crit(fmt.Sprintf("Could not make chain configuration: %v", err))
}
}
// set chain id in case it's zero.
@@ -900,7 +899,7 @@ func MakeChainDatabase(ctx *cli.Context, stack *node.Node) ethdb.Database {
chainDb, err := stack.OpenDatabase(name, cache, handles)
if err != nil {
- Fatalf("Could not open database: %v", err)
+ log.Crit(fmt.Sprintf("Could not open database: %v", err))
}
return chainDb
}
@@ -913,7 +912,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
if ctx.GlobalBool(TestNetFlag.Name) {
_, err := core.WriteTestNetGenesisBlock(chainDb)
if err != nil {
- glog.Fatalln(err)
+ log.Crit(fmt.Sprint(err))
}
}
@@ -925,7 +924,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
}
chain, err = core.NewBlockChain(chainDb, chainConfig, pow, new(event.TypeMux), vm.Config{EnablePreimageRecording: ctx.GlobalBool(VMEnableDebugFlag.Name)})
if err != nil {
- Fatalf("Could not start chainmanager: %v", err)
+ log.Crit(fmt.Sprintf("Could not start chainmanager: %v", err))
}
return chain, chainDb
}