From d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Wed, 22 Feb 2017 14:10:07 +0200 Subject: all: blidly swap out glog to our log15, logs need rework --- cmd/utils/cmd.go | 25 ++++++++++++------------- cmd/utils/flags.go | 49 ++++++++++++++++++++++++------------------------- 2 files changed, 36 insertions(+), 38 deletions(-) (limited to 'cmd/utils') 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 } -- cgit v1.2.3 From 23a5d64fd059bb8bdf02781608a15b8b1bdbdfd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Wed, 22 Feb 2017 16:58:00 +0200 Subject: accounts, cmd: port packages over to the new logging system --- cmd/utils/cmd.go | 9 --------- 1 file changed, 9 deletions(-) (limited to 'cmd/utils') diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index e288f8bd2..5baa44980 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -40,15 +40,6 @@ const ( importBatchSize = 2500 ) -func openLogFile(Datadir string, filename string) *os.File { - path := common.AbsolutePath(Datadir, filename) - file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) - if err != nil { - panic(fmt.Sprintf("error opening log file '%s': %v", filename, err)) - } - return file -} - // Fatalf formats a message to standard error and exits the program. // The message is also printed to standard output if standard error // is redirected to a different file. -- cgit v1.2.3 From 1ca20a2697e5df840a0541b61f274379b43fddc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Wed, 22 Feb 2017 17:22:50 +0200 Subject: cmd, whisper/mailserver: revert to utils.Fatalf --- cmd/utils/cmd.go | 2 +- cmd/utils/flags.go | 41 ++++++++++++++++++++--------------------- 2 files changed, 21 insertions(+), 22 deletions(-) (limited to 'cmd/utils') diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index 5baa44980..062b9c50d 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -62,7 +62,7 @@ func Fatalf(format string, args ...interface{}) { func StartNode(stack *node.Node) { if err := stack.Start(); err != nil { - log.Crit(fmt.Sprintf("Error starting protocol stack: %v", err)) + Fatalf("Error starting protocol stack: %v", err) } go func() { sigc := make(chan os.Signal, 1) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 55713c15c..a2e4ac814 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -425,7 +425,7 @@ func MakeDataDir(ctx *cli.Context) string { } return path } - log.Crit(fmt.Sprintf("Cannot determine default data directory, please set manually (--datadir)")) + Fatalf("Cannot determine default data directory, please set manually (--datadir)") return "" } @@ -451,16 +451,16 @@ func MakeNodeKey(ctx *cli.Context) *ecdsa.PrivateKey { ) switch { case file != "" && hex != "": - log.Crit(fmt.Sprintf("Options %q and %q are mutually exclusive", NodeKeyFileFlag.Name, NodeKeyHexFlag.Name)) + Fatalf("Options %q and %q are mutually exclusive", NodeKeyFileFlag.Name, NodeKeyHexFlag.Name) case file != "": if key, err = crypto.LoadECDSA(file); err != nil { - log.Crit(fmt.Sprintf("Option %q: %v", NodeKeyFileFlag.Name, err)) + Fatalf("Option %q: %v", NodeKeyFileFlag.Name, err) } case hex != "": if key, err = crypto.HexToECDSA(hex); err != nil { - log.Crit(fmt.Sprintf("Option %q: %v", NodeKeyHexFlag.Name, err)) + Fatalf("Option %q: %v", NodeKeyHexFlag.Name, err) } } return key @@ -536,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 { - log.Crit(fmt.Sprintf("Option %s: %v", NATFlag.Name, err)) + Fatalf("Option %s: %v", NATFlag.Name, err) } return natif } @@ -573,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 { - log.Crit(fmt.Sprintf("Failed to raise file descriptor allowance: %v", err)) + Fatalf("Failed to raise file descriptor allowance: %v", err) } limit, err := getFdLimit() if err != nil { - log.Crit(fmt.Sprintf("Failed to retrieve file descriptor allowance: %v", err)) + Fatalf("Failed to retrieve file descriptor allowance: %v", err) } if limit > 2048 { // cap database file descriptors even if more is available limit = 2048 @@ -619,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 { - log.Crit(fmt.Sprintf("Option %q: %v", EtherbaseFlag.Name, err)) + Fatalf("Option %q: %v", EtherbaseFlag.Name, err) } return account.Address } @@ -641,7 +641,7 @@ func MakePasswordList(ctx *cli.Context) []string { } text, err := ioutil.ReadFile(path) if err != nil { - log.Crit(fmt.Sprintf("Failed to read password file: %v", err)) + Fatalf("Failed to read password file: %v", err) } lines := strings.Split(string(text), "\n") // Sanitise DOS line endings. @@ -700,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 { - log.Crit(fmt.Sprintf("Option %q: %v", NetrestrictFlag.Name, err)) + Fatalf("Option %q: %v", NetrestrictFlag.Name, err) } config.NetRestrict = list } stack, err := node.New(config) if err != nil { - log.Crit(fmt.Sprintf("Failed to create the protocol stack: %v", err)) + Fatalf("Failed to create the protocol stack: %v", err) } return stack } @@ -723,7 +723,7 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) { } } if networks > 1 { - log.Crit(fmt.Sprintf("The %v flags are mutually exclusive", netFlags)) + Fatalf("The %v flags are mutually exclusive", netFlags) } ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore) @@ -777,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 { - log.Crit(fmt.Sprintf("Failed to register the Ethereum light node service: %v", err)) + Fatalf("Failed to register the Ethereum light node service: %v", err) } } else { if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { @@ -788,7 +788,7 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) { } return fullNode, err }); err != nil { - log.Crit(fmt.Sprintf("Failed to register the Ethereum full node service: %v", err)) + Fatalf("Failed to register the Ethereum full node service: %v", err) } } } @@ -796,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 { - log.Crit(fmt.Sprintf("Failed to register the Whisper service: %v", err)) + Fatalf("Failed to register the Whisper service: %v", err) } } @@ -813,7 +813,7 @@ func RegisterEthStatsService(stack *node.Node, url string) { return ethstats.New(url, ethServ, lesServ) }); err != nil { - log.Crit(fmt.Sprintf("Failed to register the Ethereum Stats service: %v", err)) + Fatalf("Failed to register the Ethereum Stats service: %v", err) } } @@ -844,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: - log.Crit(fmt.Sprintf("Could not make chain configuration: %v", err)) + Fatalf("Could not make chain configuration: %v", err) } } // set chain id in case it's zero. @@ -899,7 +899,7 @@ func MakeChainDatabase(ctx *cli.Context, stack *node.Node) ethdb.Database { chainDb, err := stack.OpenDatabase(name, cache, handles) if err != nil { - log.Crit(fmt.Sprintf("Could not open database: %v", err)) + Fatalf("Could not open database: %v", err) } return chainDb } @@ -912,10 +912,9 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai if ctx.GlobalBool(TestNetFlag.Name) { _, err := core.WriteTestNetGenesisBlock(chainDb) if err != nil { - log.Crit(fmt.Sprint(err)) + Fatalf("Failed to write testnet genesis: %v", err) } } - chainConfig := MakeChainConfigFromDb(ctx, chainDb) pow := pow.PoW(core.FakePow{}) @@ -924,7 +923,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 { - log.Crit(fmt.Sprintf("Could not start chainmanager: %v", err)) + Fatalf("Could not start chainmanager: %v", err) } return chain, chainDb } -- cgit v1.2.3