Skip to content

Commit

Permalink
Can't log to debug log before chain params initialized
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
laanwj committed Jul 15, 2014
1 parent 2c0f019 commit 96ff9d6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/chainparamsbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,7 @@ bool SelectBaseParamsFromCommandLine() {
}
return true;
}

bool AreBaseParamsConfigured() {
return pCurrentBaseParams != NULL;
}
6 changes: 6 additions & 0 deletions src/chainparamsbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ void SelectBaseParams(CBaseChainParams::Network network);
*/
bool SelectBaseParamsFromCommandLine();

/**
* Return true if SelectBaseParamsFromCommandLine() has been called to select
* a network.
*/
bool AreBaseParamsConfigured();

#endif
2 changes: 1 addition & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ int LogPrintStr(const std::string &str)
// print to console
ret = fwrite(str.data(), 1, str.size(), stdout);
}
else if (fPrintToDebugLog)
else if (fPrintToDebugLog && AreBaseParamsConfigured())
{
static bool fStartedNewLine = true;
boost::call_once(&DebugPrintInit, debugPrintInitFlag);
Expand Down

0 comments on commit 96ff9d6

Please sign in to comment.