2 # Copyright (c) 2017 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 """Test debug logging."""
9 from test_framework
.test_framework
import BitcoinTestFramework
11 class LoggingTest(BitcoinTestFramework
):
12 def set_test_params(self
):
14 self
.setup_clean_chain
= True
17 # test default log file name
18 assert os
.path
.isfile(os
.path
.join(self
.nodes
[0].datadir
, "regtest", "debug.log"))
20 # test alternative log file name in datadir
21 self
.restart_node(0, ["-debuglogfile=foo.log"])
22 assert os
.path
.isfile(os
.path
.join(self
.nodes
[0].datadir
, "regtest", "foo.log"))
24 # test alternative log file name outside datadir
25 tempname
= os
.path
.join(self
.options
.tmpdir
, "foo.log")
26 self
.restart_node(0, ["-debuglogfile=%s" % tempname
])
27 assert os
.path
.isfile(tempname
)
29 # check that invalid log (relative) will cause error
30 invdir
= os
.path
.join(self
.nodes
[0].datadir
, "regtest", "foo")
31 invalidname
= os
.path
.join("foo", "foo.log")
33 self
.assert_start_raises_init_error(0, ["-debuglogfile=%s" % (invalidname
)],
34 "Error: Could not open debug log file")
35 assert not os
.path
.isfile(os
.path
.join(invdir
, "foo.log"))
37 # check that invalid log (relative) works after path exists
40 self
.start_node(0, ["-debuglogfile=%s" % (invalidname
)])
41 assert os
.path
.isfile(os
.path
.join(invdir
, "foo.log"))
43 # check that invalid log (absolute) will cause error
45 invdir
= os
.path
.join(self
.options
.tmpdir
, "foo")
46 invalidname
= os
.path
.join(invdir
, "foo.log")
47 self
.assert_start_raises_init_error(0, ["-debuglogfile=%s" % invalidname
],
48 "Error: Could not open debug log file")
49 assert not os
.path
.isfile(os
.path
.join(invdir
, "foo.log"))
51 # check that invalid log (absolute) works after path exists
54 self
.start_node(0, ["-debuglogfile=%s" % (invalidname
)])
55 assert os
.path
.isfile(os
.path
.join(invdir
, "foo.log"))
58 if __name__
== '__main__':