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
This commit is contained in:
Philip Kaufmann 2013-10-08 12:09:40 +02:00
parent 42a12f22d6
commit 3b570559f8
7 changed files with 46 additions and 32 deletions

View File

@ -419,7 +419,7 @@ public:
Check(); Check();
} }
if (fRet) 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; return fRet;
} }
@ -435,7 +435,7 @@ public:
Check(); Check();
} }
if (nAdd) 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; return nAdd > 0;
} }

View File

@ -215,8 +215,18 @@ std::string HelpMessage(HelpMessageMode hmm)
#endif #endif
#endif #endif
strUsage += " -paytxfee=<amt> " + _("Fee per KB to add to transactions you send") + "\n"; 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 += " -debug=<category> " + _("Output debugging information (default: 0, supplying <category> is optional)") + "\n";
strUsage += " -debugnet " + _("Output extra network debugging information") + "\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 += " -logtimestamps " + _("Prepend debug output with timestamp") + "\n";
strUsage += " -shrinkdebugfile " + _("Shrink debug.log file on client startup (default: 1 when no -debug)") + "\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"; 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 // ********************************************************* 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); fBenchmark = GetBoolArg("-benchmark", false);
mempool.fChecks = GetBoolArg("-checkmempool", RegTest()); mempool.fChecks = GetBoolArg("-checkmempool", RegTest());
Checkpoints::fEnabled = GetBoolArg("-checkpoints", true); Checkpoints::fEnabled = GetBoolArg("-checkpoints", true);
@ -471,12 +490,6 @@ bool AppInit2(boost::thread_group& threadGroup)
else if (nScriptCheckThreads > MAX_SCRIPTCHECK_THREADS) else if (nScriptCheckThreads > MAX_SCRIPTCHECK_THREADS)
nScriptCheckThreads = MAX_SCRIPTCHECK_THREADS; nScriptCheckThreads = MAX_SCRIPTCHECK_THREADS;
// -debug implies fDebug*
if (fDebug)
fDebugNet = true;
else
fDebugNet = GetBoolArg("-debugnet", false);
if (fDaemon) if (fDaemon)
fServer = true; fServer = true;
else else

View File

@ -3544,10 +3544,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
return error("message getdata size() = %"PRIszu"", vInv.size()); 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()); 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()); LogPrint("net", "received getdata for: %s\n", vInv[0].ToString().c_str());
pfrom->vRecvGetData.insert(pfrom->vRecvGetData.end(), vInv.begin(), vInv.end()); 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; const CInv& inv = (*pto->mapAskFor.begin()).second;
if (!AlreadyHave(inv)) if (!AlreadyHave(inv))
{ {
if (fDebugNet) if (fDebug)
LogPrint("net", "sending getdata: %s\n", inv.ToString().c_str()); LogPrint("net", "sending getdata: %s\n", inv.ToString().c_str());
vGetData.push_back(inv); vGetData.push_back(inv);
if (vGetData.size() >= 1000) if (vGetData.size() >= 1000)

View File

@ -75,8 +75,7 @@ bool PaymentRequestPlus::getMerchant(X509_STORE* certStore, QString& merchant) c
digestAlgorithm = EVP_sha1(); digestAlgorithm = EVP_sha1();
} }
else if (paymentRequest.pki_type() == "none") { 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; return false;
} }
else { else {

View File

@ -87,9 +87,7 @@ static QList<QString> savedPaymentRequests;
static void ReportInvalidCertificate(const QSslCertificate& cert) 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; continue;
} }
} }
if (fDebug) qDebug() << "PaymentServer::LoadRootCAs : Loaded " << nRootCerts << " root certificates";
qDebug() << "PaymentServer::LoadRootCAs : Loaded " << nRootCerts << " root certificates";
// Project for another day: // Project for another day:
// Fetch certificate revocation lists, and add them to certStore. // Fetch certificate revocation lists, and add them to certStore.
@ -375,8 +372,7 @@ void PaymentServer::handleURIOrFile(const QString& s)
QString decoded = QUrl::fromPercentEncoding(temp); QString decoded = QUrl::fromPercentEncoding(temp);
QUrl fetchUrl(decoded, QUrl::StrictMode); QUrl fetchUrl(decoded, QUrl::StrictMode);
if (fDebug) qDebug() << "PaymentServer::handleURIOrFile : fetchRequest(" << fetchUrl << ")";
qDebug() << "PaymentServer::handleURIOrFile : fetchRequest(" << fetchUrl << ")";
if (fetchUrl.isValid()) if (fetchUrl.isValid())
fetchRequest(fetchUrl); fetchRequest(fetchUrl);
@ -475,8 +471,7 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, QList<Sen
if (request.getMerchant(PaymentServer::certStore, recipients[0].authenticatedMerchant)) { if (request.getMerchant(PaymentServer::certStore, recipients[0].authenticatedMerchant)) {
recipients[0].paymentRequest = request; recipients[0].paymentRequest = request;
recipients[0].amount = totalAmount; 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 { else {
recipients.clear(); 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 if (i == 0) // Tie request to first pay-to, we don't want multiple ACKs
recipients[i].paymentRequest = request; recipients[i].paymentRequest = request;
recipients[i].address = QString::fromStdString(CBitcoinAddress(dest).ToString()); 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 { else {
// Insecure payments to custom bitcoin addresses are not supported // Insecure payments to custom bitcoin addresses are not supported

View File

@ -73,7 +73,6 @@ using namespace std;
map<string, string> mapArgs; map<string, string> mapArgs;
map<string, vector<string> > mapMultiArgs; map<string, vector<string> > mapMultiArgs;
bool fDebug = false; bool fDebug = false;
bool fDebugNet = false;
bool fPrintToConsole = false; bool fPrintToConsole = false;
bool fPrintToDebugger = false; bool fPrintToDebugger = false;
bool fDaemon = false; bool fDaemon = false;
@ -226,10 +225,20 @@ int LogPrint(const char* category, const char* pszFormat, ...)
{ {
if (category != NULL) if (category != NULL)
{ {
if (!fDebug) return 0; if (!fDebug)
const vector<string>& categories = mapMultiArgs["-debug"];
if (find(categories.begin(), categories.end(), string(category)) == categories.end())
return 0; 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 int ret = 0; // Returns total number of characters written

View File

@ -140,7 +140,6 @@ inline void MilliSleep(int64 n)
extern std::map<std::string, std::string> mapArgs; extern std::map<std::string, std::string> mapArgs;
extern std::map<std::string, std::vector<std::string> > mapMultiArgs; extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
extern bool fDebug; extern bool fDebug;
extern bool fDebugNet;
extern bool fPrintToConsole; extern bool fPrintToConsole;
extern bool fPrintToDebugger; extern bool fPrintToDebugger;
extern bool fDaemon; extern bool fDaemon;