From cfd06195a0edbda78e114beaf5a98ff1b858937a Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Sun, 12 Feb 2012 22:14:01 +0100 Subject: [PATCH] WalletTool: allow control of logging from the command line. Change how block chain download is waited for. --- src/com/google/bitcoin/tools/WalletTool.java | 36 ++++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/com/google/bitcoin/tools/WalletTool.java b/src/com/google/bitcoin/tools/WalletTool.java index 9fcd457e..dad8a3c5 100644 --- a/src/com/google/bitcoin/tools/WalletTool.java +++ b/src/com/google/bitcoin/tools/WalletTool.java @@ -20,6 +20,7 @@ import com.google.bitcoin.core.*; import com.google.bitcoin.discovery.DnsDiscovery; import com.google.bitcoin.store.BlockStoreException; import com.google.bitcoin.store.BoundedOverheadBlockStore; +import com.google.bitcoin.utils.BriefLogFormatter; import joptsimple.OptionParser; import joptsimple.OptionSet; import joptsimple.OptionSpec; @@ -84,12 +85,10 @@ public class WalletTool { } public static void main(String[] args) throws Exception { - // Disable logspam. - LogManager.getLogManager().getLogger("").setLevel(Level.SEVERE); - OptionParser parser = new OptionParser(); parser.accepts("help"); parser.accepts("force"); + parser.accepts("debuglog"); walletFileName = parser.accepts("wallet") .withRequiredArg() .defaultsTo("wallet"); @@ -116,6 +115,13 @@ public class WalletTool { System.out.println(HELP_TEXT); return; } + + if (options.has("debuglog")) { + BriefLogFormatter.init(); + } else { + // Disable logspam unless there is a flag. + LogManager.getLogManager().getLogger("").setLevel(Level.SEVERE); + } File chainFileName; switch (netFlag.value(options)) { @@ -187,17 +193,19 @@ public class WalletTool { final int startTransactions = wallet.getTransactions(true, true).size(); peers.start(); - peers.startBlockChainDownload(new DownloadListener() { - @Override - protected void doneDownload() { - super.doneDownload(); - peers.stop(); - int endTransactions = wallet.getTransactions(true, true).size(); - if (endTransactions > startTransactions) { - System.out.println("Synced " + (endTransactions - startTransactions) + " transactions."); - } - } - }); + DownloadListener listener = new DownloadListener(); + peers.startBlockChainDownload(listener); + try { + listener.await(); + } catch (InterruptedException e) { + System.err.println("Chain download interrupted, quitting ..."); + System.exit(1); + } + peers.stop(); + int endTransactions = wallet.getTransactions(true, true).size(); + if (endTransactions > startTransactions) { + System.out.println("Synced " + (endTransactions - startTransactions) + " transactions."); + } } catch (BlockStoreException e) { System.err.println("Error reading block chain file " + chainFileName + ": " + e.getMessage()); e.printStackTrace();