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
Add -debuglogfile
option
#11781
Add -debuglogfile
option
#11781
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 |
---|---|---|
|
@@ -342,6 +342,7 @@ std::string HelpMessage(HelpMessageMode mode) | |
if (showDebug) | ||
strUsage += HelpMessageOpt("-feefilter", strprintf("Tell other nodes to filter invs to us by our mempool min fee (default: %u)", DEFAULT_FEEFILTER)); | ||
strUsage += HelpMessageOpt("-loadblock=<file>", _("Imports blocks from external blk000??.dat file on startup")); | ||
strUsage += HelpMessageOpt("-debuglogfile=<file>", strprintf(_("Specify location of debug log file: this can be an absolute path or a path relative to the data directory (default: %s)"), DEFAULT_DEBUGLOGFILE)); | ||
strUsage += HelpMessageOpt("-maxorphantx=<n>", strprintf(_("Keep at most <n> unconnectable transactions in memory (default: %u)"), DEFAULT_MAX_ORPHAN_TRANSACTIONS)); | ||
strUsage += HelpMessageOpt("-maxmempool=<n>", strprintf(_("Keep the transaction memory pool below <n> megabytes (default: %u)"), DEFAULT_MAX_MEMPOOL_SIZE)); | ||
strUsage += HelpMessageOpt("-mempoolexpiry=<n>", strprintf(_("Do not keep transactions in the mempool longer than <n> hours (default: %u)"), DEFAULT_MEMPOOL_EXPIRY)); | ||
|
@@ -1209,8 +1210,11 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) | |
ShrinkDebugFile(); | ||
} | ||
|
||
if (fPrintToDebugLog) | ||
OpenDebugLog(); | ||
if (fPrintToDebugLog) { | ||
if (!OpenDebugLog()) { | ||
return InitError(strprintf("Could not open debug log file %s", GetDebugLogPath().string())); | ||
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, missing test. 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. Will add a test, though testing this particular message only makes sense after #11783 goes in 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. Added test anyway, temporarily adding "Fix shutdown in case of errors during initialization" into here |
||
} | ||
} | ||
|
||
if (!fLogTimestamps) | ||
LogPrintf("Startup time: %s\n", DateTimeStrFormat("%Y-%m-%d %H:%M:%S", GetTime())); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ int64_t GetStartupTime(); | |
static const bool DEFAULT_LOGTIMEMICROS = false; | ||
static const bool DEFAULT_LOGIPS = false; | ||
static const bool DEFAULT_LOGTIMESTAMPS = true; | ||
extern const char * const DEFAULT_DEBUGLOGFILE; | ||
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. Would have expected this to have accompanied
lower in the file. 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. I thought about that, but it's grouped with the other 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. The others are defaults that can be overridden via an option; calling it BITCOIN_DEBUGLOG_FILENAME could make it fit by both name and type? 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. I don't get you. This is the default for 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. Same thing is true for 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. I agree! the DEFAULT_ convention is more frequently used so would make sense to use everywhere. BITCOIN_CONF_FILENAME and BITCOIN_PID_FILENAME are very old options so they didn't follow that yet. Feel free to send a patch (but not to this PR as it's pretty out of scope :-) |
||
|
||
/** Signals for translation. */ | ||
class CTranslationInterface | ||
|
@@ -180,7 +181,8 @@ void CreatePidFile(const fs::path &path, pid_t pid); | |
#ifdef WIN32 | ||
fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true); | ||
#endif | ||
void OpenDebugLog(); | ||
fs::path GetDebugLogPath(); | ||
bool OpenDebugLog(); | ||
void ShrinkDebugFile(); | ||
void runCommand(const std::string& strCommand); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2017 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
"""Test debug logging.""" | ||
|
||
import os | ||
|
||
from test_framework.test_framework import BitcoinTestFramework | ||
|
||
class LoggingTest(BitcoinTestFramework): | ||
def set_test_params(self): | ||
self.num_nodes = 1 | ||
self.setup_clean_chain = True | ||
|
||
def run_test(self): | ||
# test default log file name | ||
assert os.path.isfile(os.path.join(self.nodes[0].datadir, "regtest", "debug.log")) | ||
|
||
# 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")) | ||
|
||
# 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") | ||
invalidname = os.path.join("foo", "foo.log") | ||
self.stop_node(0) | ||
self.assert_start_raises_init_error(0, ["-debuglogfile=%s" % (invalidname)], | ||
"Error: Could not open debug log file") | ||
assert not os.path.isfile(os.path.join(invdir, "foo.log")) | ||
|
||
# check that invalid log (relative) works after path exists | ||
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: |
||
self.stop_node(0) | ||
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: not required (the previous attempt to start the node failed) |
||
os.mkdir(invdir) | ||
self.start_node(0, ["-debuglogfile=%s" % (invalidname)]) | ||
assert os.path.isfile(os.path.join(invdir, "foo.log")) | ||
|
||
# check that invalid log (absolute) will cause error | ||
self.stop_node(0) | ||
invdir = os.path.join(self.options.tmpdir, "foo") | ||
invalidname = os.path.join(invdir, "foo.log") | ||
self.assert_start_raises_init_error(0, ["-debuglogfile=%s" % invalidname], | ||
"Error: Could not open debug log file") | ||
assert not os.path.isfile(os.path.join(invdir, "foo.log")) | ||
|
||
# check that invalid log (absolute) works after path exists | ||
self.stop_node(0) | ||
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: not required (the previous attempt to start the node failed) |
||
os.mkdir(invdir) | ||
self.start_node(0, ["-debuglogfile=%s" % (invalidname)]) | ||
assert os.path.isfile(os.path.join(invdir, "foo.log")) | ||
|
||
|
||
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.
Can you update the text to say that this can be absolute or relative (just like you have for the help text:
this can be an absolute path or a path relative to the data directory
)?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.
The release notes are not documentation. This minor change does not warrant a long write-up in the release notes. If anyone wants to have documentation they can just look at bitcoind's help which is documentation.