mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-12 05:34:57 +01:00
Change LogAcceptCategory to use uint32_t rather than sets of strings.
This changes the logging categories to boolean flags instead of strings. This simplifies the acceptance testing by avoiding accessing a scoped static thread local pointer to a thread local set of strings. It eliminates the only use of boost::thread_specific_ptr outside of lockorder debugging. This change allows log entries to be directed to multiple categories and makes it easy to change the logging flags at runtime (e.g. via an RPC, though that isn't done by this commit.) It also eliminates the fDebug global. Configuration of unknown logging categories now produces a warning.
This commit is contained in:
28
src/init.cpp
28
src/init.cpp
@@ -312,7 +312,7 @@ void OnRPCStopped()
|
||||
uiInterface.NotifyBlockTip.disconnect(&RPCNotifyBlockChange);
|
||||
RPCNotifyBlockChange(false, nullptr);
|
||||
cvBlockChange.notify_all();
|
||||
LogPrint("rpc", "RPC stopped.\n");
|
||||
LogPrint(BCLog::RPC, "RPC stopped.\n");
|
||||
}
|
||||
|
||||
void OnRPCPreCommand(const CRPCCommand& cmd)
|
||||
@@ -441,11 +441,8 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
strUsage += HelpMessageOpt("-limitdescendantsize=<n>", strprintf("Do not accept transactions if any ancestor would have more than <n> kilobytes of in-mempool descendants (default: %u).", DEFAULT_DESCENDANT_SIZE_LIMIT));
|
||||
strUsage += HelpMessageOpt("-bip9params=deployment:start:end", "Use given start/end times for specified BIP9 deployment (regtest-only)");
|
||||
}
|
||||
std::string debugCategories = "addrman, alert, bench, cmpctblock, coindb, db, http, leveldb, libevent, lock, mempool, mempoolrej, net, proxy, prune, rand, reindex, rpc, selectcoins, tor, zmq"; // Don't translate these and qt below
|
||||
if (mode == HMM_BITCOIN_QT)
|
||||
debugCategories += ", qt";
|
||||
strUsage += HelpMessageOpt("-debug=<category>", strprintf(_("Output debugging information (default: %u, supplying <category> is optional)"), 0) + ". " +
|
||||
_("If <category> is not supplied or if <category> = 1, output all debugging information.") + _("<category> can be:") + " " + debugCategories + ".");
|
||||
_("If <category> is not supplied or if <category> = 1, output all debugging information.") + " " + _("<category> can be:") + " " + ListLogCategories() + ".");
|
||||
if (showDebug)
|
||||
strUsage += HelpMessageOpt("-nodebug", "Turn off debugging messages, same as -debug=0");
|
||||
strUsage += HelpMessageOpt("-help-debug", _("Show all debugging options (usage: --help -help-debug)"));
|
||||
@@ -909,12 +906,19 @@ bool AppInitParameterInteraction()
|
||||
|
||||
// ********************************************************* Step 3: parameter-to-internal-flags
|
||||
|
||||
fDebug = mapMultiArgs.count("-debug");
|
||||
// Special-case: if -debug=0/-nodebug is set, turn off debugging messages
|
||||
if (fDebug) {
|
||||
if (mapMultiArgs.count("-debug") > 0) {
|
||||
// Special-case: if -debug=0/-nodebug is set, turn off debugging messages
|
||||
const std::vector<std::string>& categories = mapMultiArgs.at("-debug");
|
||||
if (GetBoolArg("-nodebug", false) || find(categories.begin(), categories.end(), std::string("0")) != categories.end())
|
||||
fDebug = false;
|
||||
|
||||
if (!(GetBoolArg("-nodebug", false) || find(categories.begin(), categories.end(), std::string("0")) != categories.end())) {
|
||||
for (const auto& cat : categories) {
|
||||
uint32_t flag;
|
||||
if (!GetLogCategory(&flag, &cat)) {
|
||||
InitWarning(strprintf(_("Unsupported logging category %s.\n"), cat));
|
||||
}
|
||||
logCategories |= flag;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check for -debugnet
|
||||
@@ -1168,7 +1172,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
#ifndef WIN32
|
||||
CreatePidFile(GetPidFile(), getpid());
|
||||
#endif
|
||||
if (GetBoolArg("-shrinkdebugfile", !fDebug)) {
|
||||
if (GetBoolArg("-shrinkdebugfile", logCategories != BCLog::NONE)) {
|
||||
// Do this first since it both loads a bunch of debug.log into memory,
|
||||
// and because this needs to happen before any other debug.log printing
|
||||
ShrinkDebugFile();
|
||||
@@ -1492,7 +1496,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
break;
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
if (fDebug) LogPrintf("%s\n", e.what());
|
||||
LogPrintf("%s\n", e.what());
|
||||
strLoadError = _("Error opening block database");
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user