Skip to content

Commit ef4b518

Browse files
committed
Merge pull request #3067 from Diapolo/debug-switch
re-work -debug switch handling
2 parents 033ffc4 + 3b57055 commit ef4b518

File tree

7 files changed

+46
-32
lines changed

7 files changed

+46
-32
lines changed

src/addrman.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ class CAddrMan
419419
Check();
420420
}
421421
if (fRet)
422-
LogPrint("addr", "Added %s from %s: %i tried, %i new\n", addr.ToStringIPPort().c_str(), source.ToString().c_str(), nTried, nNew);
422+
LogPrint("addrman", "Added %s from %s: %i tried, %i new\n", addr.ToStringIPPort().c_str(), source.ToString().c_str(), nTried, nNew);
423423
return fRet;
424424
}
425425

@@ -435,7 +435,7 @@ class CAddrMan
435435
Check();
436436
}
437437
if (nAdd)
438-
LogPrint("addr", "Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString().c_str(), nTried, nNew);
438+
LogPrint("addrman", "Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString().c_str(), nTried, nNew);
439439
return nAdd > 0;
440440
}
441441

src/init.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,18 @@ std::string HelpMessage(HelpMessageMode hmm)
215215
#endif
216216
#endif
217217
strUsage += " -paytxfee=<amt> " + _("Fee per KB to add to transactions you send") + "\n";
218-
strUsage += " -debug " + _("Output extra debugging information. Implies all other -debug* options") + "\n";
219-
strUsage += " -debugnet " + _("Output extra network debugging information") + "\n";
218+
strUsage += " -debug=<category> " + _("Output debugging information (default: 0, supplying <category> is optional)") + "\n";
219+
strUsage += _("If <category> is not supplied, output all debugging information.") + "\n";
220+
strUsage += _("<category> can be:");
221+
strUsage += " addrman, alert, coindb, db, lock, rand, rpc, selectcoins, mempool, net"; // Don't translate these and qt below
222+
if (hmm == HMM_BITCOIN_QT)
223+
{
224+
strUsage += ", qt.\n";
225+
}
226+
else
227+
{
228+
strUsage += ".\n";
229+
}
220230
strUsage += " -logtimestamps " + _("Prepend debug output with timestamp") + "\n";
221231
strUsage += " -shrinkdebugfile " + _("Shrink debug.log file on client startup (default: 1 when no -debug)") + "\n";
222232
strUsage += " -printtoconsole " + _("Send trace/debug info to console instead of debug.log file") + "\n";
@@ -457,7 +467,16 @@ bool AppInit2(boost::thread_group& threadGroup)
457467

458468
// ********************************************************* Step 3: parameter-to-internal-flags
459469

460-
if (mapMultiArgs.count("-debug")) fDebug = true;
470+
fDebug = !mapMultiArgs["-debug"].empty();
471+
// Special-case: if -debug=0/-nodebug is set, turn off debugging messages
472+
const vector<string>& categories = mapMultiArgs["-debug"];
473+
if (GetBoolArg("-nodebug", false) || find(categories.begin(), categories.end(), string("0")) != categories.end())
474+
fDebug = false;
475+
476+
// Check for -debugnet (deprecated)
477+
if (GetBoolArg("-debugnet", false))
478+
InitWarning(_("Warning: Deprecated argument -debugnet ignored, use -debug=net"));
479+
461480
fBenchmark = GetBoolArg("-benchmark", false);
462481
mempool.fChecks = GetBoolArg("-checkmempool", RegTest());
463482
Checkpoints::fEnabled = GetBoolArg("-checkpoints", true);
@@ -471,12 +490,6 @@ bool AppInit2(boost::thread_group& threadGroup)
471490
else if (nScriptCheckThreads > MAX_SCRIPTCHECK_THREADS)
472491
nScriptCheckThreads = MAX_SCRIPTCHECK_THREADS;
473492

474-
// -debug implies fDebug*
475-
if (fDebug)
476-
fDebugNet = true;
477-
else
478-
fDebugNet = GetBoolArg("-debugnet", false);
479-
480493
if (fDaemon)
481494
fServer = true;
482495
else

src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3544,10 +3544,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
35443544
return error("message getdata size() = %"PRIszu"", vInv.size());
35453545
}
35463546

3547-
if (fDebugNet || (vInv.size() != 1))
3547+
if (fDebug || (vInv.size() != 1))
35483548
LogPrint("net", "received getdata (%"PRIszu" invsz)\n", vInv.size());
35493549

3550-
if ((fDebugNet && vInv.size() > 0) || (vInv.size() == 1))
3550+
if ((fDebug && vInv.size() > 0) || (vInv.size() == 1))
35513551
LogPrint("net", "received getdata for: %s\n", vInv[0].ToString().c_str());
35523552

35533553
pfrom->vRecvGetData.insert(pfrom->vRecvGetData.end(), vInv.begin(), vInv.end());
@@ -4213,7 +4213,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
42134213
const CInv& inv = (*pto->mapAskFor.begin()).second;
42144214
if (!AlreadyHave(inv))
42154215
{
4216-
if (fDebugNet)
4216+
if (fDebug)
42174217
LogPrint("net", "sending getdata: %s\n", inv.ToString().c_str());
42184218
vGetData.push_back(inv);
42194219
if (vGetData.size() >= 1000)

src/qt/paymentrequestplus.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ bool PaymentRequestPlus::getMerchant(X509_STORE* certStore, QString& merchant) c
7575
digestAlgorithm = EVP_sha1();
7676
}
7777
else if (paymentRequest.pki_type() == "none") {
78-
if (fDebug)
79-
qDebug() << "PaymentRequestPlus::getMerchant : Payment request: pki_type == none";
78+
qDebug() << "PaymentRequestPlus::getMerchant : Payment request: pki_type == none";
8079
return false;
8180
}
8281
else {

src/qt/paymentserver.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ static QList<QString> savedPaymentRequests;
8787

8888
static void ReportInvalidCertificate(const QSslCertificate& cert)
8989
{
90-
if (fDebug) {
91-
qDebug() << "ReportInvalidCertificate : Payment server found an invalid certificate: " << cert.subjectInfo(QSslCertificate::CommonName);
92-
}
90+
qDebug() << "ReportInvalidCertificate : Payment server found an invalid certificate: " << cert.subjectInfo(QSslCertificate::CommonName);
9391
}
9492

9593
//
@@ -160,8 +158,7 @@ void PaymentServer::LoadRootCAs(X509_STORE* _store)
160158
continue;
161159
}
162160
}
163-
if (fDebug)
164-
qDebug() << "PaymentServer::LoadRootCAs : Loaded " << nRootCerts << " root certificates";
161+
qDebug() << "PaymentServer::LoadRootCAs : Loaded " << nRootCerts << " root certificates";
165162

166163
// Project for another day:
167164
// Fetch certificate revocation lists, and add them to certStore.
@@ -375,8 +372,7 @@ void PaymentServer::handleURIOrFile(const QString& s)
375372
QString decoded = QUrl::fromPercentEncoding(temp);
376373
QUrl fetchUrl(decoded, QUrl::StrictMode);
377374

378-
if (fDebug)
379-
qDebug() << "PaymentServer::handleURIOrFile : fetchRequest(" << fetchUrl << ")";
375+
qDebug() << "PaymentServer::handleURIOrFile : fetchRequest(" << fetchUrl << ")";
380376

381377
if (fetchUrl.isValid())
382378
fetchRequest(fetchUrl);
@@ -475,8 +471,7 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, QList<Sen
475471
if (request.getMerchant(PaymentServer::certStore, recipients[0].authenticatedMerchant)) {
476472
recipients[0].paymentRequest = request;
477473
recipients[0].amount = totalAmount;
478-
if (fDebug)
479-
qDebug() << "PaymentServer::processPaymentRequest : Payment request from " << recipients[0].authenticatedMerchant;
474+
qDebug() << "PaymentServer::processPaymentRequest : Payment request from " << recipients[0].authenticatedMerchant;
480475
}
481476
else {
482477
recipients.clear();
@@ -493,8 +488,7 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, QList<Sen
493488
if (i == 0) // Tie request to first pay-to, we don't want multiple ACKs
494489
recipients[i].paymentRequest = request;
495490
recipients[i].address = QString::fromStdString(CBitcoinAddress(dest).ToString());
496-
if (fDebug)
497-
qDebug() << "PaymentServer::processPaymentRequest : Payment request, insecure " << recipients[i].address;
491+
qDebug() << "PaymentServer::processPaymentRequest : Payment request, insecure " << recipients[i].address;
498492
}
499493
else {
500494
// Insecure payments to custom bitcoin addresses are not supported

src/util.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ using namespace std;
7373
map<string, string> mapArgs;
7474
map<string, vector<string> > mapMultiArgs;
7575
bool fDebug = false;
76-
bool fDebugNet = false;
7776
bool fPrintToConsole = false;
7877
bool fPrintToDebugger = false;
7978
bool fDaemon = false;
@@ -226,10 +225,20 @@ int LogPrint(const char* category, const char* pszFormat, ...)
226225
{
227226
if (category != NULL)
228227
{
229-
if (!fDebug) return 0;
230-
const vector<string>& categories = mapMultiArgs["-debug"];
231-
if (find(categories.begin(), categories.end(), string(category)) == categories.end())
228+
if (!fDebug)
232229
return 0;
230+
231+
const vector<string>& categories = mapMultiArgs["-debug"];
232+
bool allCategories = count(categories.begin(), categories.end(), string(""));
233+
234+
// Only look for categories, if not -debug/-debug=1 was passed,
235+
// as that implies every category should be logged.
236+
if (!allCategories)
237+
{
238+
// Category was not found (not supplied via -debug=<category>)
239+
if (find(categories.begin(), categories.end(), string(category)) == categories.end())
240+
return 0;
241+
}
233242
}
234243

235244
int ret = 0; // Returns total number of characters written

src/util.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ inline void MilliSleep(int64 n)
140140
extern std::map<std::string, std::string> mapArgs;
141141
extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
142142
extern bool fDebug;
143-
extern bool fDebugNet;
144143
extern bool fPrintToConsole;
145144
extern bool fPrintToDebugger;
146145
extern bool fDaemon;

0 commit comments

Comments
 (0)