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 /cmd | |
parent | 61e6bb12478740d614c8effd330f881f962b7b84 (diff) | |
download | dexon-23a5d64fd059bb8bdf02781608a15b8b1bdbdfd2.tar.gz dexon-23a5d64fd059bb8bdf02781608a15b8b1bdbdfd2.tar.zst dexon-23a5d64fd059bb8bdf02781608a15b8b1bdbdfd2.zip |
accounts, cmd: port packages over to the new logging system
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/bootnode/main.go | 20 | ||||
-rw-r--r-- | cmd/ethtest/main.go | 30 | ||||
-rw-r--r-- | cmd/geth/accountcmd.go | 4 | ||||
-rw-r--r-- | cmd/geth/accountcmd_test.go | 16 | ||||
-rw-r--r-- | cmd/utils/cmd.go | 9 |
5 files changed, 38 insertions, 41 deletions
diff --git a/cmd/bootnode/main.go b/cmd/bootnode/main.go index f8cc77f83..31b2726be 100644 --- a/cmd/bootnode/main.go +++ b/cmd/bootnode/main.go @@ -56,28 +56,28 @@ func main() { natm, err := nat.Parse(*natdesc) if err != nil { - log.Crit(fmt.Sprintf("-nat: %v", err)) + log.Crit("Failed to parse requested NAT", "error", err) } switch { case *genKey != "": nodeKey, err = crypto.GenerateKey() if err != nil { - log.Crit(fmt.Sprintf("could not generate key: %v", err)) + log.Crit("Failed to generate new key", "error", err) } if err = crypto.SaveECDSA(*genKey, nodeKey); err != nil { - log.Crit(fmt.Sprintf("%v", err)) + log.Crit("Failed to save generated key", "error", err) } case *nodeKeyFile == "" && *nodeKeyHex == "": - log.Crit(fmt.Sprintf("Use -nodekey or -nodekeyhex to specify a private key")) + log.Crit("Use -nodekey or -nodekeyhex to load a private key") case *nodeKeyFile != "" && *nodeKeyHex != "": - log.Crit(fmt.Sprintf("Options -nodekey and -nodekeyhex are mutually exclusive")) + log.Crit("Options -nodekey and -nodekeyhex are mutually exclusive") case *nodeKeyFile != "": if nodeKey, err = crypto.LoadECDSA(*nodeKeyFile); err != nil { - log.Crit(fmt.Sprintf("-nodekey: %v", err)) + log.Crit("Failed to loading the key file", "path", *nodeKeyFile, "error", err) } case *nodeKeyHex != "": if nodeKey, err = crypto.HexToECDSA(*nodeKeyHex); err != nil { - log.Crit(fmt.Sprintf("-nodekeyhex: %v", err)) + log.Crit("Failed to parse the key hex", "hex", *nodeKeyHex, "error", err) } } @@ -90,17 +90,17 @@ func main() { if *netrestrict != "" { restrictList, err = netutil.ParseNetlist(*netrestrict) if err != nil { - log.Crit(fmt.Sprintf("-netrestrict: %v", err)) + log.Crit("Failed to parse the network restrictions", "error", err) } } if *runv5 { if _, err := discv5.ListenUDP(nodeKey, *listenAddr, natm, "", restrictList); err != nil { - log.Crit(fmt.Sprintf("%v", err)) + log.Crit("Failed to start the v5 discovery protocol", "error", err) } } else { if _, err := discover.ListenUDP(nodeKey, *listenAddr, natm, "", restrictList); err != nil { - log.Crit(fmt.Sprintf("%v", err)) + log.Crit("Failed to start the discovery protocol", "error", err) } } diff --git a/cmd/ethtest/main.go b/cmd/ethtest/main.go index a107c701f..fcae668c6 100644 --- a/cmd/ethtest/main.go +++ b/cmd/ethtest/main.go @@ -70,7 +70,8 @@ var ( ) func runTestWithReader(test string, r io.Reader) error { - log.Info(fmt.Sprint("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) { - log.Info(fmt.Sprint("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()) - log.Info(fmt.Sprint("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 { - log.Info(fmt.Sprint("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 { - log.Crit(fmt.Sprint(err)) + suiteLogger.Crit("Failed to gather files", "error", err) } if len(files) == 0 { - log.Warn("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 { - log.Crit(fmt.Sprint(err)) + testLogger.Crit("Failed to open file") } defer r.Close() err = runTestWithReader(curTest, r) if err != nil { if continueOnError { - log.Error(fmt.Sprint(err)) + testLogger.Error("Test failed, continuing", "error", err) } else { - log.Crit(fmt.Sprint(err)) + testLogger.Crit("Test failed, aborting", "error", err) } } } @@ -189,9 +194,7 @@ func setupApp(c *cli.Context) error { if !useStdIn { runSuite(flagTest, flagFile) } else { - if err := runTestWithReader(flagTest, os.Stdin); err != nil { - log.Crit(fmt.Sprint(err)) - } + return runTestWithReader(flagTest, os.Stdin) } return nil } @@ -216,7 +219,6 @@ func main() { } if err := app.Run(os.Args); err != nil { - log.Crit(fmt.Sprint(err)) + log.Crit("Failed to run the tester", "error", err) } - } diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go index b7c411e82..0b0be7938 100644 --- a/cmd/geth/accountcmd.go +++ b/cmd/geth/accountcmd.go @@ -204,11 +204,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 { - log.Info(fmt.Sprintf("Unlocked account %x", account.Address)) + log.Info("Unlocked account", "address", account.Address.Hex()) return account, password } if err, ok := err.(*keystore.AmbiguousAddrError); ok { - log.Info(fmt.Sprintf("Unlocked account %x", account.Address)) + log.Info("Unlocked account", "address", account.Address.Hex()) return ambiguousAddrRecovery(ks, err, password), password } if err != keystore.ErrDecrypt { 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/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. |