Skip to content

Commit 96ff9d6

Browse files
committed
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`.
1 parent 2c0f019 commit 96ff9d6

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/chainparamsbase.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,7 @@ bool SelectBaseParamsFromCommandLine() {
9191
}
9292
return true;
9393
}
94+
95+
bool AreBaseParamsConfigured() {
96+
return pCurrentBaseParams != NULL;
97+
}

src/chainparamsbase.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,10 @@ void SelectBaseParams(CBaseChainParams::Network network);
4949
*/
5050
bool SelectBaseParamsFromCommandLine();
5151

52+
/**
53+
* Return true if SelectBaseParamsFromCommandLine() has been called to select
54+
* a network.
55+
*/
56+
bool AreBaseParamsConfigured();
57+
5258
#endif

src/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ int LogPrintStr(const std::string &str)
205205
// print to console
206206
ret = fwrite(str.data(), 1, str.size(), stdout);
207207
}
208-
else if (fPrintToDebugLog)
208+
else if (fPrintToDebugLog && AreBaseParamsConfigured())
209209
{
210210
static bool fStartedNewLine = true;
211211
boost::call_once(&DebugPrintInit, debugPrintInitFlag);

0 commit comments

Comments
 (0)