aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-02-23 22:49:05 +0800
committerGitHub <noreply@github.com>2017-02-23 22:49:05 +0800
commit357732a8404c9fe4d02f041d20a0d05381a3e6d1 (patch)
treeedaf8a63eb7f7434cd9b9cbd764b3c4c3d76191e /cmd
parent29fac7de448c85049a97cbec3dc0819122bd2cb0 (diff)
parentf89dd627760b43bd405cb3db1e5efdb100835db5 (diff)
downloaddexon-357732a8404c9fe4d02f041d20a0d05381a3e6d1.tar
dexon-357732a8404c9fe4d02f041d20a0d05381a3e6d1.tar.gz
dexon-357732a8404c9fe4d02f041d20a0d05381a3e6d1.tar.bz2
dexon-357732a8404c9fe4d02f041d20a0d05381a3e6d1.tar.lz
dexon-357732a8404c9fe4d02f041d20a0d05381a3e6d1.tar.xz
dexon-357732a8404c9fe4d02f041d20a0d05381a3e6d1.tar.zst
dexon-357732a8404c9fe4d02f041d20a0d05381a3e6d1.zip
Merge pull request #3696 from karalabe/contextual-logger
Contextual logger
Diffstat (limited to 'cmd')
-rw-r--r--cmd/bootnode/main.go12
-rw-r--r--cmd/ethtest/main.go34
-rw-r--r--cmd/evm/main.go7
-rw-r--r--cmd/geth/accountcmd.go8
-rw-r--r--cmd/geth/accountcmd_test.go16
-rw-r--r--cmd/geth/chaincmd.go9
-rw-r--r--cmd/geth/main.go17
-rw-r--r--cmd/gethrpctest/main.go21
-rw-r--r--cmd/swarm/main.go9
-rw-r--r--cmd/swarm/manifest.go91
-rw-r--r--cmd/swarm/upload.go4
-rw-r--r--cmd/utils/cmd.go32
-rw-r--r--cmd/utils/flags.go12
-rw-r--r--cmd/wnode/main.go8
14 files changed, 131 insertions, 149 deletions
diff --git a/cmd/bootnode/main.go b/cmd/bootnode/main.go
index 9b5ba1936..c3fc163a1 100644
--- a/cmd/bootnode/main.go
+++ b/cmd/bootnode/main.go
@@ -25,7 +25,7 @@ import (
"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"
@@ -42,15 +42,19 @@ 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)
diff --git a/cmd/ethtest/main.go b/cmd/ethtest/main.go
index 14b839579..fcae668c6 100644
--- a/cmd/ethtest/main.go
+++ b/cmd/ethtest/main.go
@@ -25,7 +25,7 @@ import (
"path/filepath"
"strings"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/tests"
"gopkg.in/urfave/cli.v1"
@@ -70,7 +70,8 @@ var (
)
func runTestWithReader(test string, r io.Reader) error {
- glog.Infoln("runTest", test)
+ log.Info("Running test", "test", test)
+
var err error
switch strings.ToLower(test) {
case "bk", "block", "blocktest", "blockchaintest", "blocktests", "blockchaintests":
@@ -92,7 +93,8 @@ func runTestWithReader(test string, r io.Reader) error {
}
func getFiles(path string) ([]string, error) {
- glog.Infoln("getFiles", path)
+ log.Info("Listing files", "path", path)
+
var files []string
f, err := os.Open(path)
if err != nil {
@@ -113,7 +115,7 @@ func getFiles(path string) ([]string, error) {
// only go 1 depth and leave directory entires blank
if !v.IsDir() && v.Name()[len(v.Name())-len(testExtension):len(v.Name())] == testExtension {
files[i] = filepath.Join(path, v.Name())
- glog.Infoln("Found file", files[i])
+ log.Info("Found test file", "file", files[i])
}
}
case mode.IsRegular():
@@ -134,7 +136,9 @@ func runSuite(test, file string) {
}
for _, curTest := range tests {
- glog.Infoln("runSuite", curTest, file)
+ suiteLogger := log.New("suite", file, "test", curTest)
+ suiteLogger.Info("Running test suite")
+
var err error
var files []string
if test == defaultTest {
@@ -149,30 +153,31 @@ func runSuite(test, file string) {
files, err = getFiles(file)
}
if err != nil {
- glog.Fatalln(err)
+ suiteLogger.Crit("Failed to gather files", "error", err)
}
if len(files) == 0 {
- glog.Warningln("No files matched path")
+ suiteLogger.Warn("No files matched path")
}
for _, curFile := range files {
// Skip blank entries
if len(curFile) == 0 {
continue
}
+ testLogger := suiteLogger.New("file", curFile)
r, err := os.Open(curFile)
if err != nil {
- glog.Fatalln(err)
+ testLogger.Crit("Failed to open file")
}
defer r.Close()
err = runTestWithReader(curTest, r)
if err != nil {
if continueOnError {
- glog.Errorln(err)
+ testLogger.Error("Test failed, continuing", "error", err)
} else {
- glog.Fatalln(err)
+ testLogger.Crit("Test failed, aborting", "error", err)
}
}
}
@@ -189,15 +194,13 @@ func setupApp(c *cli.Context) error {
if !useStdIn {
runSuite(flagTest, flagFile)
} else {
- if err := runTestWithReader(flagTest, os.Stdin); err != nil {
- glog.Fatalln(err)
- }
+ return runTestWithReader(flagTest, os.Stdin)
}
return nil
}
func main() {
- glog.SetToStderr(true)
+ log.Root().SetHandler(log.StreamHandler(os.Stderr, log.TerminalFormat()))
app := cli.NewApp()
app.Name = "ethtest"
@@ -216,7 +219,6 @@ func main() {
}
if err := app.Run(os.Args); err != nil {
- glog.Fatalln(err)
+ log.Crit("Failed to run the tester", "error", err)
}
-
}
diff --git a/cmd/evm/main.go b/cmd/evm/main.go
index 0693d7cd3..86e2493ca 100644
--- a/cmd/evm/main.go
+++ b/cmd/evm/main.go
@@ -30,7 +30,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/core/vm/runtime"
"github.com/ethereum/go-ethereum/ethdb"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"gopkg.in/urfave/cli.v1"
)
@@ -111,8 +111,9 @@ func init() {
}
func run(ctx *cli.Context) error {
- glog.SetToStderr(true)
- glog.SetV(ctx.GlobalInt(VerbosityFlag.Name))
+ glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.TerminalFormat()))
+ glogger.Verbosity(log.Lvl(ctx.GlobalInt(VerbosityFlag.Name)))
+ log.Root().SetHandler(glogger)
var (
db, _ = ethdb.NewMemDatabase()
diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go
index cd398eadb..f86be62ba 100644
--- a/cmd/geth/accountcmd.go
+++ b/cmd/geth/accountcmd.go
@@ -25,8 +25,7 @@ import (
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/console"
"github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"gopkg.in/urfave/cli.v1"
)
@@ -203,11 +202,11 @@ func unlockAccount(ctx *cli.Context, ks *keystore.KeyStore, address string, i in
password := getPassPhrase(prompt, false, i, passwords)
err = ks.Unlock(account, password)
if err == nil {
- glog.V(logger.Info).Infof("Unlocked account %x", account.Address)
+ log.Info("Unlocked account", "address", account.Address.Hex())
return account, password
}
if err, ok := err.(*keystore.AmbiguousAddrError); ok {
- glog.V(logger.Info).Infof("Unlocked account %x", account.Address)
+ log.Info("Unlocked account", "address", account.Address.Hex())
return ambiguousAddrRecovery(ks, err, password), password
}
if err != keystore.ErrDecrypt {
@@ -217,6 +216,7 @@ func unlockAccount(ctx *cli.Context, ks *keystore.KeyStore, address string, i in
}
// All trials expended to unlock account, bail out
utils.Fatalf("Failed to unlock account %s (%v)", address, err)
+
return accounts.Account{}, ""
}
diff --git a/cmd/geth/accountcmd_test.go b/cmd/geth/accountcmd_test.go
index 679a7ec30..adcb72454 100644
--- a/cmd/geth/accountcmd_test.go
+++ b/cmd/geth/accountcmd_test.go
@@ -145,7 +145,8 @@ Passphrase: {{.InputLine "foobar"}}
geth.expectExit()
wantMessages := []string{
- "Unlocked account f466859ead1932d743d622cb74fc058882e8648a",
+ "Unlocked account",
+ "=0xf466859ead1932d743d622cb74fc058882e8648a",
}
for _, m := range wantMessages {
if !strings.Contains(geth.stderrText(), m) {
@@ -189,8 +190,9 @@ Passphrase: {{.InputLine "foobar"}}
geth.expectExit()
wantMessages := []string{
- "Unlocked account 7ef5a6135f1fd6a02593eedc869c6d41d934aef8",
- "Unlocked account 289d485d9771714cce91d3393d764e1311907acc",
+ "Unlocked account",
+ "=0x7ef5a6135f1fd6a02593eedc869c6d41d934aef8",
+ "=0x289d485d9771714cce91d3393d764e1311907acc",
}
for _, m := range wantMessages {
if !strings.Contains(geth.stderrText(), m) {
@@ -208,8 +210,9 @@ func TestUnlockFlagPasswordFile(t *testing.T) {
geth.expectExit()
wantMessages := []string{
- "Unlocked account 7ef5a6135f1fd6a02593eedc869c6d41d934aef8",
- "Unlocked account 289d485d9771714cce91d3393d764e1311907acc",
+ "Unlocked account",
+ "=0x7ef5a6135f1fd6a02593eedc869c6d41d934aef8",
+ "=0x289d485d9771714cce91d3393d764e1311907acc",
}
for _, m := range wantMessages {
if !strings.Contains(geth.stderrText(), m) {
@@ -257,7 +260,8 @@ In order to avoid this warning, you need to remove the following duplicate key f
geth.expectExit()
wantMessages := []string{
- "Unlocked account f466859ead1932d743d622cb74fc058882e8648a",
+ "Unlocked account",
+ "=0xf466859ead1932d743d622cb74fc058882e8648a",
}
for _, m := range wantMessages {
if !strings.Contains(geth.stderrText(), m) {
diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go
index f38ee046f..74950697c 100644
--- a/cmd/geth/chaincmd.go
+++ b/cmd/geth/chaincmd.go
@@ -32,8 +32,7 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/trie"
"github.com/syndtr/goleveldb/leveldb/util"
"gopkg.in/urfave/cli.v1"
@@ -129,7 +128,7 @@ func initGenesis(ctx *cli.Context) error {
if err != nil {
utils.Fatalf("failed to write genesis block: %v", err)
}
- glog.V(logger.Info).Infof("successfully wrote genesis block and/or chain rule set: %x", block.Hash())
+ log.Info(fmt.Sprintf("successfully wrote genesis block and/or chain rule set: %x", block.Hash()))
return nil
}
@@ -257,7 +256,7 @@ func removeDB(ctx *cli.Context) error {
}
func upgradeDB(ctx *cli.Context) error {
- glog.Infoln("Upgrading blockchain database")
+ log.Info(fmt.Sprint("Upgrading blockchain database"))
stack := utils.MakeNode(ctx, clientIdentifier, gitCommit)
chain, chainDb := utils.MakeChain(ctx, stack)
@@ -286,7 +285,7 @@ func upgradeDB(ctx *cli.Context) error {
utils.Fatalf("Import error %v (a backup is made in %s, use the import command to import it)", err, exportFile)
} else {
os.Remove(exportFile)
- glog.Infoln("Import finished")
+ log.Info(fmt.Sprint("Import finished"))
}
return nil
}
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index 7d98f6bb2..803a618f1 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -34,8 +34,7 @@ import (
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethclient"
"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/metrics"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"
@@ -204,11 +203,11 @@ func makeFullNode(ctx *cli.Context) *node.Node {
}{uint(params.VersionMajor<<16 | params.VersionMinor<<8 | params.VersionPatch), clientIdentifier, runtime.Version(), runtime.GOOS}
extra, err := rlp.EncodeToBytes(clientInfo)
if err != nil {
- glog.V(logger.Warn).Infoln("error setting canonical miner information:", err)
+ log.Warn(fmt.Sprint("error setting canonical miner information:", err))
}
if uint64(len(extra)) > params.MaximumExtraDataSize {
- glog.V(logger.Warn).Infoln("error setting canonical miner information: extra exceeds", params.MaximumExtraDataSize)
- glog.V(logger.Debug).Infof("extra: %x\n", extra)
+ log.Warn(fmt.Sprint("error setting canonical miner information: extra exceeds", params.MaximumExtraDataSize))
+ log.Debug(fmt.Sprintf("extra: %x\n", extra))
extra = nil
}
stack := utils.MakeNode(ctx, clientIdentifier, gitCommit)
@@ -273,7 +272,7 @@ func startNode(ctx *cli.Context, stack *node.Node) {
// Open and self derive any wallets already attached
for _, wallet := range stack.AccountManager().Wallets() {
if err := wallet.Open(""); err != nil {
- glog.V(logger.Warn).Infof("Failed to open wallet %s: %v", wallet.URL(), err)
+ log.Warn(fmt.Sprintf("Failed to open wallet %s: %v", wallet.URL(), err))
} else {
wallet.SelfDerive(accounts.DefaultBaseDerivationPath, stateReader)
}
@@ -282,13 +281,13 @@ func startNode(ctx *cli.Context, stack *node.Node) {
for event := range events {
if event.Arrive {
if err := event.Wallet.Open(""); err != nil {
- glog.V(logger.Info).Infof("New wallet appeared: %s, failed to open: %s", event.Wallet.URL(), err)
+ log.Info(fmt.Sprintf("New wallet appeared: %s, failed to open: %s", event.Wallet.URL(), err))
} else {
- glog.V(logger.Info).Infof("New wallet appeared: %s, %s", event.Wallet.URL(), event.Wallet.Status())
+ log.Info(fmt.Sprintf("New wallet appeared: %s, %s", event.Wallet.URL(), event.Wallet.Status()))
event.Wallet.SelfDerive(accounts.DefaultBaseDerivationPath, stateReader)
}
} else {
- glog.V(logger.Info).Infof("Old wallet dropped: %s", event.Wallet.URL())
+ log.Info(fmt.Sprintf("Old wallet dropped: %s", event.Wallet.URL()))
event.Wallet.Close()
}
}
diff --git a/cmd/gethrpctest/main.go b/cmd/gethrpctest/main.go
index 9e80ad05d..69a6074e7 100644
--- a/cmd/gethrpctest/main.go
+++ b/cmd/gethrpctest/main.go
@@ -19,7 +19,7 @@ package main
import (
"flag"
- "log"
+ "fmt"
"os"
"os/signal"
@@ -27,7 +27,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethdb"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/tests"
@@ -46,35 +46,34 @@ func main() {
flag.Parse()
// Enable logging errors, we really do want to see those
- glog.SetV(2)
- glog.SetToStderr(true)
+ log.Root().SetHandler(log.LvlFilterHandler(log.LvlError, log.StreamHandler(os.Stderr, log.TerminalFormat())))
// Load the test suite to run the RPC against
tests, err := tests.LoadBlockTests(*testFile)
if err != nil {
- log.Fatalf("Failed to load test suite: %v", err)
+ log.Crit(fmt.Sprintf("Failed to load test suite: %v", err))
}
test, found := tests[*testName]
if !found {
- log.Fatalf("Requested test (%s) not found within suite", *testName)
+ log.Crit(fmt.Sprintf("Requested test (%s) not found within suite", *testName))
}
stack, err := MakeSystemNode(*testKey, test)
if err != nil {
- log.Fatalf("Failed to assemble test stack: %v", err)
+ log.Crit(fmt.Sprintf("Failed to assemble test stack: %v", err))
}
if err := stack.Start(); err != nil {
- log.Fatalf("Failed to start test node: %v", err)
+ log.Crit(fmt.Sprintf("Failed to start test node: %v", err))
}
defer stack.Stop()
- log.Println("Test node started...")
+ log.Info("Test node started...")
// Make sure the tests contained within the suite pass
if err := RunTest(stack, test); err != nil {
- log.Fatalf("Failed to run the pre-configured test: %v", err)
+ log.Crit(fmt.Sprintf("Failed to run the pre-configured test: %v", err))
}
- log.Println("Initial test suite passed...")
+ log.Info("Initial test suite passed...")
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go
index 5661b3f6e..12cad328f 100644
--- a/cmd/swarm/main.go
+++ b/cmd/swarm/main.go
@@ -35,8 +35,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"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/p2p"
"github.com/ethereum/go-ethereum/p2p/discover"
@@ -278,7 +277,7 @@ func bzzd(ctx *cli.Context) error {
signal.Notify(sigc, syscall.SIGTERM)
defer signal.Stop(sigc)
<-sigc
- glog.V(logger.Info).Infoln("Got sigterm, shutting down...")
+ log.Info(fmt.Sprint("Got sigterm, shutting down..."))
stack.Stop()
}()
networkId := ctx.GlobalUint64(SwarmNetworkIdFlag.Name)
@@ -343,7 +342,7 @@ func getAccount(ctx *cli.Context, stack *node.Node) *ecdsa.PrivateKey {
}
// Try to load the arg as a hex key file.
if key, err := crypto.LoadECDSA(keyid); err == nil {
- glog.V(logger.Info).Infof("swarm account key loaded: %#x", crypto.PubkeyToAddress(key.PublicKey))
+ log.Info(fmt.Sprintf("swarm account key loaded: %#x", crypto.PubkeyToAddress(key.PublicKey)))
return key
}
// Otherwise try getting it from the keystore.
@@ -400,7 +399,7 @@ func injectBootnodes(srv *p2p.Server, nodes []string) {
for _, url := range nodes {
n, err := discover.ParseNode(url)
if err != nil {
- glog.Errorf("invalid bootnode %q", err)
+ log.Error(fmt.Sprintf("invalid bootnode %q", err))
continue
}
srv.AddPeer(n)
diff --git a/cmd/swarm/manifest.go b/cmd/swarm/manifest.go
index 0de0d69bb..f64792689 100644
--- a/cmd/swarm/manifest.go
+++ b/cmd/swarm/manifest.go
@@ -18,13 +18,14 @@
package main
import (
- "gopkg.in/urfave/cli.v1"
+ "encoding/json"
+ "fmt"
"log"
"mime"
"path/filepath"
"strings"
- "fmt"
- "encoding/json"
+
+ "gopkg.in/urfave/cli.v1"
)
func add(ctx *cli.Context) {
@@ -35,23 +36,22 @@ func add(ctx *cli.Context) {
}
var (
- mhash = args[0]
- path = args[1]
- hash = args[2]
+ mhash = args[0]
+ path = args[1]
+ hash = args[2]
- ctype string
+ ctype string
wantManifest = ctx.GlobalBoolT(SwarmWantManifestFlag.Name)
- mroot manifest
+ mroot manifest
)
-
if len(args) > 3 {
ctype = args[3]
} else {
ctype = mime.TypeByExtension(filepath.Ext(path))
}
- newManifest := addEntryToManifest (ctx, mhash, path, hash, ctype)
+ newManifest := addEntryToManifest(ctx, mhash, path, hash, ctype)
fmt.Println(newManifest)
if !wantManifest {
@@ -70,13 +70,13 @@ func update(ctx *cli.Context) {
}
var (
- mhash = args[0]
- path = args[1]
- hash = args[2]
+ mhash = args[0]
+ path = args[1]
+ hash = args[2]
- ctype string
+ ctype string
wantManifest = ctx.GlobalBoolT(SwarmWantManifestFlag.Name)
- mroot manifest
+ mroot manifest
)
if len(args) > 3 {
ctype = args[3]
@@ -84,7 +84,7 @@ func update(ctx *cli.Context) {
ctype = mime.TypeByExtension(filepath.Ext(path))
}
- newManifest := updateEntryInManifest (ctx, mhash, path, hash, ctype)
+ newManifest := updateEntryInManifest(ctx, mhash, path, hash, ctype)
fmt.Println(newManifest)
if !wantManifest {
@@ -102,14 +102,14 @@ func remove(ctx *cli.Context) {
}
var (
- mhash = args[0]
- path = args[1]
+ mhash = args[0]
+ path = args[1]
wantManifest = ctx.GlobalBoolT(SwarmWantManifestFlag.Name)
- mroot manifest
+ mroot manifest
)
- newManifest := removeEntryFromManifest (ctx, mhash, path)
+ newManifest := removeEntryFromManifest(ctx, mhash, path)
fmt.Println(newManifest)
if !wantManifest {
@@ -120,15 +120,15 @@ func remove(ctx *cli.Context) {
}
}
-func addEntryToManifest(ctx *cli.Context, mhash , path, hash , ctype string) string {
+func addEntryToManifest(ctx *cli.Context, mhash, path, hash, ctype string) string {
var (
- bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
- client = &client{api: bzzapi}
+ bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
+ client = &client{api: bzzapi}
longestPathEntry = manifestEntry{
Path: "",
Hash: "",
- ContentType: "",
+ ContentType: "",
}
)
@@ -143,12 +143,11 @@ func addEntryToManifest(ctx *cli.Context, mhash , path, hash , ctype string) st
log.Fatalln("hash to add is not present:", err)
}
-
// See if we path is in this Manifest or do we have to dig deeper
for _, entry := range mroot.Entries {
if path == entry.Path {
log.Fatal(path, "Already present, not adding anything")
- }else {
+ } else {
if entry.ContentType == "application/bzz-manifest+json" {
prfxlen := strings.HasPrefix(path, entry.Path)
if prfxlen && len(path) > len(longestPathEntry.Path) {
@@ -161,7 +160,7 @@ func addEntryToManifest(ctx *cli.Context, mhash , path, hash , ctype string) st
if longestPathEntry.Path != "" {
// Load the child Manifest add the entry there
newPath := path[len(longestPathEntry.Path):]
- newHash := addEntryToManifest (ctx, longestPathEntry.Hash, newPath, hash, ctype)
+ newHash := addEntryToManifest(ctx, longestPathEntry.Hash, newPath, hash, ctype)
// Replace the hash for parent Manifests
newMRoot := manifest{}
@@ -182,31 +181,28 @@ func addEntryToManifest(ctx *cli.Context, mhash , path, hash , ctype string) st
mroot.Entries = append(mroot.Entries, newEntry)
}
-
newManifestHash, err := client.uploadManifest(mroot)
if err != nil {
log.Fatalln("manifest upload failed:", err)
}
return newManifestHash
-
-
}
-func updateEntryInManifest(ctx *cli.Context, mhash , path, hash , ctype string) string {
+func updateEntryInManifest(ctx *cli.Context, mhash, path, hash, ctype string) string {
var (
- bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
- client = &client{api: bzzapi}
+ bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
+ client = &client{api: bzzapi}
newEntry = manifestEntry{
Path: "",
Hash: "",
- ContentType: "",
+ ContentType: "",
}
longestPathEntry = manifestEntry{
Path: "",
Hash: "",
- ContentType: "",
+ ContentType: "",
}
)
@@ -217,12 +213,11 @@ func updateEntryInManifest(ctx *cli.Context, mhash , path, hash , ctype string)
//TODO: check if the "hash" with which to update is valid and present in swarm
-
// See if we path is in this Manifest or do we have to dig deeper
for _, entry := range mroot.Entries {
if path == entry.Path {
newEntry = entry
- }else {
+ } else {
if entry.ContentType == "application/bzz-manifest+json" {
prfxlen := strings.HasPrefix(path, entry.Path)
if prfxlen && len(path) > len(longestPathEntry.Path) {
@@ -239,7 +234,7 @@ func updateEntryInManifest(ctx *cli.Context, mhash , path, hash , ctype string)
if longestPathEntry.Path != "" {
// Load the child Manifest add the entry there
newPath := path[len(longestPathEntry.Path):]
- newHash := updateEntryInManifest (ctx, longestPathEntry.Hash, newPath, hash, ctype)
+ newHash := updateEntryInManifest(ctx, longestPathEntry.Hash, newPath, hash, ctype)
// Replace the hash for parent Manifests
newMRoot := manifest{}
@@ -271,7 +266,6 @@ func updateEntryInManifest(ctx *cli.Context, mhash , path, hash , ctype string)
mroot = newMRoot
}
-
newManifestHash, err := client.uploadManifest(mroot)
if err != nil {
log.Fatalln("manifest upload failed:", err)
@@ -279,20 +273,20 @@ func updateEntryInManifest(ctx *cli.Context, mhash , path, hash , ctype string)
return newManifestHash
}
-func removeEntryFromManifest(ctx *cli.Context, mhash , path string) string {
+func removeEntryFromManifest(ctx *cli.Context, mhash, path string) string {
var (
- bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
- client = &client{api: bzzapi}
+ bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
+ client = &client{api: bzzapi}
entryToRemove = manifestEntry{
Path: "",
Hash: "",
- ContentType: "",
+ ContentType: "",
}
longestPathEntry = manifestEntry{
Path: "",
Hash: "",
- ContentType: "",
+ ContentType: "",
}
)
@@ -301,13 +295,11 @@ func removeEntryFromManifest(ctx *cli.Context, mhash , path string) string {
log.Fatalln("manifest download failed:", err)
}
-
-
// See if we path is in this Manifest or do we have to dig deeper
for _, entry := range mroot.Entries {
if path == entry.Path {
entryToRemove = entry
- }else {
+ } else {
if entry.ContentType == "application/bzz-manifest+json" {
prfxlen := strings.HasPrefix(path, entry.Path)
if prfxlen && len(path) > len(longestPathEntry.Path) {
@@ -324,7 +316,7 @@ func removeEntryFromManifest(ctx *cli.Context, mhash , path string) string {
if longestPathEntry.Path != "" {
// Load the child Manifest remove the entry there
newPath := path[len(longestPathEntry.Path):]
- newHash := removeEntryFromManifest (ctx, longestPathEntry.Hash, newPath)
+ newHash := removeEntryFromManifest(ctx, longestPathEntry.Hash, newPath)
// Replace the hash for parent Manifests
newMRoot := manifest{}
@@ -348,13 +340,10 @@ func removeEntryFromManifest(ctx *cli.Context, mhash , path string) string {
mroot = newMRoot
}
-
newManifestHash, err := client.uploadManifest(mroot)
if err != nil {
log.Fatalln("manifest upload failed:", err)
}
return newManifestHash
-
}
-
diff --git a/cmd/swarm/upload.go b/cmd/swarm/upload.go
index 871713b2d..9f3a2abe0 100644
--- a/cmd/swarm/upload.go
+++ b/cmd/swarm/upload.go
@@ -233,7 +233,7 @@ func (c *client) postRaw(mimetype string, size int64, body io.ReadCloser) (strin
func (c *client) downloadManifest(mhash string) (manifest, error) {
mroot := manifest{}
- req, err := http.NewRequest("GET", c.api + "/bzzr:/" + mhash, nil)
+ req, err := http.NewRequest("GET", c.api+"/bzzr:/"+mhash, nil)
if err != nil {
return mroot, err
}
@@ -254,4 +254,4 @@ func (c *client) downloadManifest(mhash string) (manifest, error) {
return mroot, fmt.Errorf("Manifest %v is malformed: %v", mhash, err)
}
return mroot, err
-} \ No newline at end of file
+}
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index 8666f3775..062b9c50d 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"
)
@@ -41,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.
@@ -79,12 +69,12 @@ func StartNode(stack *node.Node) {
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 +105,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 +118,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 +166,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 +188,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 +204,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 +227,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..a2e4ac814 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"
@@ -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)
@@ -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)
@@ -913,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 {
- glog.Fatalln(err)
+ Fatalf("Failed to write testnet genesis: %v", err)
}
}
-
chainConfig := MakeChainConfigFromDb(ctx, chainDb)
pow := pow.PoW(core.FakePow{})
diff --git a/cmd/wnode/main.go b/cmd/wnode/main.go
index d002497fb..8191f9292 100644
--- a/cmd/wnode/main.go
+++ b/cmd/wnode/main.go
@@ -36,8 +36,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/console"
"github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/nat"
@@ -82,7 +81,7 @@ var (
testMode = flag.Bool("t", false, "use of predefined parameters for diagnostics")
generateKey = flag.Bool("k", false, "generate and show the private key")
- argVerbosity = flag.Int("verbosity", logger.Warn, "log verbosity level")
+ argVerbosity = flag.Int("verbosity", int(log.LvlWarn), "log verbosity level")
argTTL = flag.Uint("ttl", 30, "time-to-live for messages in seconds")
argWorkTime = flag.Uint("work", 5, "work time in seconds")
argPoW = flag.Float64("pow", whisper.MinimumPoW, "PoW for normal messages in float format (e.g. 2.7)")
@@ -153,8 +152,7 @@ func echo() {
}
func initialize() {
- glog.SetV(*argVerbosity)
- glog.SetToStderr(true)
+ log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(*argVerbosity), log.StreamHandler(os.Stderr, log.TerminalFormat())))
done = make(chan struct{})
var peers []*discover.Node