New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Print to console by default when not run with -daemon #13004
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -815,14 +815,25 @@ static std::string ResolveErrMsg(const char * const optname, const std::string& | |
return strprintf(_("Cannot resolve -%s address: '%s'"), optname, strBind); | ||
} | ||
|
||
/** | ||
* Initialize global loggers. | ||
* | ||
* Note that this is called very early in the process lifetime, so you should be | ||
* careful about what global state you rely on here. | ||
*/ | ||
void InitLogging() | ||
{ | ||
fPrintToConsole = gArgs.GetBoolArg("-printtoconsole", false); | ||
// Add newlines to the logfile to distinguish this execution from the last | ||
// one; called before console logging is set up, so this is only sent to | ||
// debug.log. | ||
LogPrintf("\n\n\n\n\n"); | ||
|
||
fPrintToConsole = gArgs.GetBoolArg("-printtoconsole", !gArgs.GetBoolArg("-daemon", false)); | ||
fPrintToDebugLog = !gArgs.IsArgNegated("-debuglogfile"); | ||
fLogTimestamps = gArgs.GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS); | ||
fLogTimeMicros = gArgs.GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS); | ||
fLogIPs = gArgs.GetBoolArg("-logips", DEFAULT_LOGIPS); | ||
|
||
LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); | ||
std::string version_string = FormatFullVersion(); | ||
#ifdef DEBUG | ||
version_string += " (debug build)"; | ||
|
@@ -1216,13 +1227,12 @@ bool AppInitMain() | |
#ifndef WIN32 | ||
CreatePidFile(GetPidFile(), getpid()); | ||
#endif | ||
if (gArgs.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(); | ||
} | ||
|
||
if (fPrintToDebugLog) { | ||
if (gArgs.GetBoolArg("-shrinkdebugfile", logCategories == BCLog::NONE)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoa - good catch to move this inside the |
||
// 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(); | ||
} | ||
if (!OpenDebugLog()) { | ||
return InitError(strprintf("Could not open debug log file %s", GetDebugLogPath().string())); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,21 +15,25 @@ def set_test_params(self): | |
self.num_nodes = 1 | ||
self.setup_clean_chain = True | ||
|
||
def relative_log_path(self, name): | ||
return os.path.join(self.nodes[0].datadir, "regtest", name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: IIRC |
||
|
||
def run_test(self): | ||
# test default log file name | ||
assert os.path.isfile(os.path.join(self.nodes[0].datadir, "regtest", "debug.log")) | ||
default_log_path = self.relative_log_path("debug.log") | ||
assert os.path.isfile(default_log_path) | ||
|
||
# test alternative log file name in datadir | ||
self.restart_node(0, ["-debuglogfile=foo.log"]) | ||
assert os.path.isfile(os.path.join(self.nodes[0].datadir, "regtest", "foo.log")) | ||
assert os.path.isfile(self.relative_log_path("foo.log")) | ||
|
||
# test alternative log file name outside datadir | ||
tempname = os.path.join(self.options.tmpdir, "foo.log") | ||
self.restart_node(0, ["-debuglogfile=%s" % tempname]) | ||
assert os.path.isfile(tempname) | ||
|
||
# check that invalid log (relative) will cause error | ||
invdir = os.path.join(self.nodes[0].datadir, "regtest", "foo") | ||
invdir = self.relative_log_path("foo") | ||
invalidname = os.path.join("foo", "foo.log") | ||
self.stop_node(0) | ||
exp_stderr = "Error: Could not open debug log file \S+$" | ||
|
@@ -55,6 +59,17 @@ def run_test(self): | |
self.start_node(0, ["-debuglogfile=%s" % (invalidname)]) | ||
assert os.path.isfile(os.path.join(invdir, "foo.log")) | ||
|
||
# check that -nodebuglogfile disables logging | ||
self.stop_node(0) | ||
os.unlink(default_log_path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Could use the identical and more clear "remove", since unlink seems to be some unix specific thing, but we also run the tests on windows. |
||
assert not os.path.isfile(default_log_path) | ||
self.start_node(0, ["-nodebuglogfile"]) | ||
assert not os.path.isfile(default_log_path) | ||
|
||
# just sanity check no crash here | ||
self.stop_node(0) | ||
self.start_node(0, ["-debuglogfile=%s" % os.devnull]) | ||
|
||
|
||
if __name__ == '__main__': | ||
LoggingTest().main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, won't it print these newlines even if
fPrintToDebugLog
ends up being false?