diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index fedfd2ad93619..da891bdb41981 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -141,6 +141,8 @@ UniValue debug(const JSONRPCRequest& request) fDebug = GetArg("-debug", "") != "0"; + ResetLogAcceptCategoryCache(); + return "Debug mode: " + (fDebug ? strMode : "off"); } diff --git a/src/util.cpp b/src/util.cpp index 5977476252bf0..7229ed29e3153 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -216,6 +216,7 @@ static boost::once_flag debugPrintInitFlag = BOOST_ONCE_INIT; static FILE* fileout = NULL; static boost::mutex* mutexDebugLog = NULL; static std::list* vMsgsBeforeOpenLog; +static std::atomic logAcceptCategoryCacheCounter(0); static int FileWriteStr(const std::string &str, FILE *fp) { @@ -260,6 +261,7 @@ bool LogAcceptCategory(const char* category) // where mapMultiArgs might be deleted before another // global destructor calls LogPrint() static boost::thread_specific_ptr > ptrCategory; + static boost::thread_specific_ptr cacheCounter; if (!fDebug) { if (ptrCategory.get() != NULL) { @@ -269,8 +271,11 @@ bool LogAcceptCategory(const char* category) return false; } - if (ptrCategory.get() == NULL) + if (ptrCategory.get() == NULL || *cacheCounter != logAcceptCategoryCacheCounter.load()) { + cacheCounter.reset(new int(logAcceptCategoryCacheCounter.load())); + + LOCK(cs_args); if (mapMultiArgs.count("-debug")) { std::string strThreadName = GetThreadName(); LogPrintf("debug turned on:\n"); @@ -309,6 +314,11 @@ bool LogAcceptCategory(const char* category) return true; } +void ResetLogAcceptCategoryCache() +{ + logAcceptCategoryCacheCounter++; +} + /** * fStartedNewLine is a state variable held by the calling context that will * suppress printing of the timestamp when multiple calls are made that don't diff --git a/src/util.h b/src/util.h index 7c7978ff9c758..d8c53f858b857 100644 --- a/src/util.h +++ b/src/util.h @@ -91,6 +91,8 @@ bool SetupNetworking(); /** Return true if log accepts specified category */ bool LogAcceptCategory(const char* category); +/** Reset internal log category caching (call this when debug categories have changed) */ +void ResetLogAcceptCategoryCache(); /** Send a string to the log output */ int LogPrintStr(const std::string &str);