Can't log to debug log before chain params initialized

Add a function `AreBaseParamsConfigured` and use this to check
before writing to the debug log. This avoids assertions when the
application happens to log too early, which happens in the GUI.

Messages logged before the base parameters are configured can be
shown using `-printtoconsole`.
pull/4534/head
Wladimir J. van der Laan 10 years ago
parent 2c0f019bfc
commit 96ff9d6403

@ -91,3 +91,7 @@ bool SelectBaseParamsFromCommandLine() {
} }
return true; return true;
} }
bool AreBaseParamsConfigured() {
return pCurrentBaseParams != NULL;
}

@ -49,4 +49,10 @@ void SelectBaseParams(CBaseChainParams::Network network);
*/ */
bool SelectBaseParamsFromCommandLine(); bool SelectBaseParamsFromCommandLine();
/**
* Return true if SelectBaseParamsFromCommandLine() has been called to select
* a network.
*/
bool AreBaseParamsConfigured();
#endif #endif

@ -205,7 +205,7 @@ int LogPrintStr(const std::string &str)
// print to console // print to console
ret = fwrite(str.data(), 1, str.size(), stdout); ret = fwrite(str.data(), 1, str.size(), stdout);
} }
else if (fPrintToDebugLog) else if (fPrintToDebugLog && AreBaseParamsConfigured())
{ {
static bool fStartedNewLine = true; static bool fStartedNewLine = true;
boost::call_once(&DebugPrintInit, debugPrintInitFlag); boost::call_once(&DebugPrintInit, debugPrintInitFlag);

Loading…
Cancel
Save