aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Kaufmann <phil.kaufmann@t-online.de>2013-10-08 12:09:40 +0200
committerPhilip Kaufmann <phil.kaufmann@t-online.de>2013-10-30 16:02:09 +0100
commit3b570559f8d39a5d4cffd01b8091c3133f7750dc (patch)
tree1aed798318d5b7f3677492570e8398d14e449a41
parent42a12f22d6b644fcd879da23f6e56c310eb9985f (diff)
downloadbitcoin-3b570559f8d39a5d4cffd01b8091c3133f7750dc.tar.xz
re-work -debug switch handling
- re-work -debug help message text - make -debug log every debugging information again (even all categories) - remove unneeded fDebug checks in front of LogPrint()/qDebug(), as that check is done in LogPrintf() when category is != NULL (true for all LogPrint() calls - remove fDebug ONLY in code which is NOT performance-critical - harmonize addrman category name - deprecate -debugnet usage, should be used via -debug=net and remove the corresponding global
-rw-r--r--src/addrman.h4
-rw-r--r--src/init.cpp31
-rw-r--r--src/main.cpp6
-rw-r--r--src/qt/paymentrequestplus.cpp3
-rw-r--r--src/qt/paymentserver.cpp16
-rw-r--r--src/util.cpp17
-rw-r--r--src/util.h1
7 files changed, 46 insertions, 32 deletions
diff --git a/src/addrman.h b/src/addrman.h
index 081543ace4..d703e1091e 100644
--- a/src/addrman.h
+++ b/src/addrman.h
@@ -419,7 +419,7 @@ public:
Check();
}
if (fRet)
- LogPrint("addr", "Added %s from %s: %i tried, %i new\n", addr.ToStringIPPort().c_str(), source.ToString().c_str(), nTried, nNew);
+ LogPrint("addrman", "Added %s from %s: %i tried, %i new\n", addr.ToStringIPPort().c_str(), source.ToString().c_str(), nTried, nNew);
return fRet;
}
@@ -435,7 +435,7 @@ public:
Check();
}
if (nAdd)
- LogPrint("addr", "Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString().c_str(), nTried, nNew);
+ LogPrint("addrman", "Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString().c_str(), nTried, nNew);
return nAdd > 0;
}
diff --git a/src/init.cpp b/src/init.cpp
index 72b53ebecc..647b8d52ea 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -215,8 +215,18 @@ std::string HelpMessage(HelpMessageMode hmm)
#endif
#endif
strUsage += " -paytxfee=<amt> " + _("Fee per KB to add to transactions you send") + "\n";
- strUsage += " -debug " + _("Output extra debugging information. Implies all other -debug* options") + "\n";
- strUsage += " -debugnet " + _("Output extra network debugging information") + "\n";
+ strUsage += " -debug=<category> " + _("Output debugging information (default: 0, supplying <category> is optional)") + "\n";
+ strUsage += _("If <category> is not supplied, output all debugging information.") + "\n";
+ strUsage += _("<category> can be:");
+ strUsage += " addrman, alert, coindb, db, lock, rand, rpc, selectcoins, mempool, net"; // Don't translate these and qt below
+ if (hmm == HMM_BITCOIN_QT)
+ {
+ strUsage += ", qt.\n";
+ }
+ else
+ {
+ strUsage += ".\n";
+ }
strUsage += " -logtimestamps " + _("Prepend debug output with timestamp") + "\n";
strUsage += " -shrinkdebugfile " + _("Shrink debug.log file on client startup (default: 1 when no -debug)") + "\n";
strUsage += " -printtoconsole " + _("Send trace/debug info to console instead of debug.log file") + "\n";
@@ -457,7 +467,16 @@ bool AppInit2(boost::thread_group& threadGroup)
// ********************************************************* Step 3: parameter-to-internal-flags
- if (mapMultiArgs.count("-debug")) fDebug = true;
+ fDebug = !mapMultiArgs["-debug"].empty();
+ // Special-case: if -debug=0/-nodebug is set, turn off debugging messages
+ const vector<string>& categories = mapMultiArgs["-debug"];
+ if (GetBoolArg("-nodebug", false) || find(categories.begin(), categories.end(), string("0")) != categories.end())
+ fDebug = false;
+
+ // Check for -debugnet (deprecated)
+ if (GetBoolArg("-debugnet", false))
+ InitWarning(_("Warning: Deprecated argument -debugnet ignored, use -debug=net"));
+
fBenchmark = GetBoolArg("-benchmark", false);
mempool.fChecks = GetBoolArg("-checkmempool", RegTest());
Checkpoints::fEnabled = GetBoolArg("-checkpoints", true);
@@ -471,12 +490,6 @@ bool AppInit2(boost::thread_group& threadGroup)
else if (nScriptCheckThreads > MAX_SCRIPTCHECK_THREADS)
nScriptCheckThreads = MAX_SCRIPTCHECK_THREADS;
- // -debug implies fDebug*
- if (fDebug)
- fDebugNet = true;
- else
- fDebugNet = GetBoolArg("-debugnet", false);
-
if (fDaemon)
fServer = true;
else
diff --git a/src/main.cpp b/src/main.cpp
index 3d339b4fdd..640fbac8bb 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -3544,10 +3544,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
return error("message getdata size() = %"PRIszu"", vInv.size());
}
- if (fDebugNet || (vInv.size() != 1))
+ if (fDebug || (vInv.size() != 1))
LogPrint("net", "received getdata (%"PRIszu" invsz)\n", vInv.size());
- if ((fDebugNet && vInv.size() > 0) || (vInv.size() == 1))
+ if ((fDebug && vInv.size() > 0) || (vInv.size() == 1))
LogPrint("net", "received getdata for: %s\n", vInv[0].ToString().c_str());
pfrom->vRecvGetData.insert(pfrom->vRecvGetData.end(), vInv.begin(), vInv.end());
@@ -4213,7 +4213,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
const CInv& inv = (*pto->mapAskFor.begin()).second;
if (!AlreadyHave(inv))
{
- if (fDebugNet)
+ if (fDebug)
LogPrint("net", "sending getdata: %s\n", inv.ToString().c_str());
vGetData.push_back(inv);
if (vGetData.size() >= 1000)
diff --git a/src/qt/paymentrequestplus.cpp b/src/qt/paymentrequestplus.cpp
index f6a898ff7c..c8afd837d2 100644
--- a/src/qt/paymentrequestplus.cpp
+++ b/src/qt/paymentrequestplus.cpp
@@ -75,8 +75,7 @@ bool PaymentRequestPlus::getMerchant(X509_STORE* certStore, QString& merchant) c
digestAlgorithm = EVP_sha1();
}
else if (paymentRequest.pki_type() == "none") {
- if (fDebug)
- qDebug() << "PaymentRequestPlus::getMerchant : Payment request: pki_type == none";
+ qDebug() << "PaymentRequestPlus::getMerchant : Payment request: pki_type == none";
return false;
}
else {
diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp
index 43c4bdd191..0f386680ac 100644
--- a/src/qt/paymentserver.cpp
+++ b/src/qt/paymentserver.cpp
@@ -87,9 +87,7 @@ static QList<QString> savedPaymentRequests;
static void ReportInvalidCertificate(const QSslCertificate& cert)
{
- if (fDebug) {
- qDebug() << "ReportInvalidCertificate : Payment server found an invalid certificate: " << cert.subjectInfo(QSslCertificate::CommonName);
- }
+ qDebug() << "ReportInvalidCertificate : Payment server found an invalid certificate: " << cert.subjectInfo(QSslCertificate::CommonName);
}
//
@@ -160,8 +158,7 @@ void PaymentServer::LoadRootCAs(X509_STORE* _store)
continue;
}
}
- if (fDebug)
- qDebug() << "PaymentServer::LoadRootCAs : Loaded " << nRootCerts << " root certificates";
+ qDebug() << "PaymentServer::LoadRootCAs : Loaded " << nRootCerts << " root certificates";
// Project for another day:
// Fetch certificate revocation lists, and add them to certStore.
@@ -375,8 +372,7 @@ void PaymentServer::handleURIOrFile(const QString& s)
QString decoded = QUrl::fromPercentEncoding(temp);
QUrl fetchUrl(decoded, QUrl::StrictMode);
- if (fDebug)
- qDebug() << "PaymentServer::handleURIOrFile : fetchRequest(" << fetchUrl << ")";
+ qDebug() << "PaymentServer::handleURIOrFile : fetchRequest(" << fetchUrl << ")";
if (fetchUrl.isValid())
fetchRequest(fetchUrl);
@@ -475,8 +471,7 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, QList<Sen
if (request.getMerchant(PaymentServer::certStore, recipients[0].authenticatedMerchant)) {
recipients[0].paymentRequest = request;
recipients[0].amount = totalAmount;
- if (fDebug)
- qDebug() << "PaymentServer::processPaymentRequest : Payment request from " << recipients[0].authenticatedMerchant;
+ qDebug() << "PaymentServer::processPaymentRequest : Payment request from " << recipients[0].authenticatedMerchant;
}
else {
recipients.clear();
@@ -493,8 +488,7 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, QList<Sen
if (i == 0) // Tie request to first pay-to, we don't want multiple ACKs
recipients[i].paymentRequest = request;
recipients[i].address = QString::fromStdString(CBitcoinAddress(dest).ToString());
- if (fDebug)
- qDebug() << "PaymentServer::processPaymentRequest : Payment request, insecure " << recipients[i].address;
+ qDebug() << "PaymentServer::processPaymentRequest : Payment request, insecure " << recipients[i].address;
}
else {
// Insecure payments to custom bitcoin addresses are not supported
diff --git a/src/util.cpp b/src/util.cpp
index 71994587cf..9ee1ad5f52 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -73,7 +73,6 @@ using namespace std;
map<string, string> mapArgs;
map<string, vector<string> > mapMultiArgs;
bool fDebug = false;
-bool fDebugNet = false;
bool fPrintToConsole = false;
bool fPrintToDebugger = false;
bool fDaemon = false;
@@ -226,10 +225,20 @@ int LogPrint(const char* category, const char* pszFormat, ...)
{
if (category != NULL)
{
- if (!fDebug) return 0;
- const vector<string>& categories = mapMultiArgs["-debug"];
- if (find(categories.begin(), categories.end(), string(category)) == categories.end())
+ if (!fDebug)
return 0;
+
+ const vector<string>& categories = mapMultiArgs["-debug"];
+ bool allCategories = count(categories.begin(), categories.end(), string(""));
+
+ // Only look for categories, if not -debug/-debug=1 was passed,
+ // as that implies every category should be logged.
+ if (!allCategories)
+ {
+ // Category was not found (not supplied via -debug=<category>)
+ if (find(categories.begin(), categories.end(), string(category)) == categories.end())
+ return 0;
+ }
}
int ret = 0; // Returns total number of characters written
diff --git a/src/util.h b/src/util.h
index 258910e2fb..2573694046 100644
--- a/src/util.h
+++ b/src/util.h
@@ -140,7 +140,6 @@ inline void MilliSleep(int64 n)
extern std::map<std::string, std::string> mapArgs;
extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
extern bool fDebug;
-extern bool fDebugNet;
extern bool fPrintToConsole;
extern bool fPrintToDebugger;
extern bool fDaemon;