1
+ #!/usr/bin/env python3
2
+ # Copyright (c) 2017 The Bitcoin Core developers
3
+ # Copyright (c) 20200 The PIVX Core developers
4
+ # Distributed under the MIT software license, see the accompanying
5
+ # file COPYING or http://www.opensource.org/licenses/mit-license.php.
6
+ """Test debug logging."""
7
+
8
+ import os
9
+
10
+ from test_framework .test_framework import PivxTestFramework
11
+
12
+ class LoggingTest (PivxTestFramework ):
13
+ def set_test_params (self ):
14
+ self .num_nodes = 1
15
+ self .setup_clean_chain = True
16
+
17
+ def run_test (self ):
18
+ # test default log file name
19
+ assert os .path .isfile (os .path .join (self .nodes [0 ].datadir , "regtest" , "debug.log" ))
20
+ self .log .info ("Default filename ok" )
21
+
22
+ # test alternative log file name in datadir
23
+ self .restart_node (0 , ["-debuglogfile=foo.log" ])
24
+ assert os .path .isfile (os .path .join (self .nodes [0 ].datadir , "regtest" , "foo.log" ))
25
+ self .log .info ("Alternative filename ok" )
26
+
27
+ # test alternative log file name outside datadir
28
+ tempname = os .path .join (self .options .tmpdir , "foo.log" )
29
+ self .restart_node (0 , ["-debuglogfile=%s" % tempname ])
30
+ assert os .path .isfile (tempname )
31
+ self .log .info ("Alternative filename outside datadir ok" )
32
+
33
+ # check that invalid log (relative) will cause error
34
+ self .stop_node (0 )
35
+ self .assert_start_raises_init_error (0 , ["-debuglogfile=ssdksjdf/sdasdfa/sdfsdfsfd" ],
36
+ "Error: Could not open debug log file" )
37
+ self .log .info ("Invalid relative filename throws" )
38
+
39
+ # check that invalid log (absolute) will cause error
40
+ self .stop_node (0 )
41
+ invalidname = os .path .join (self .options .tmpdir , "foo/foo.log" )
42
+ self .assert_start_raises_init_error (0 , ["-debuglogfile=%s" % invalidname ],
43
+ "Error: Could not open debug log file" )
44
+ self .log .info ("Invalid absolute filename throws" )
45
+
46
+
47
+ if __name__ == '__main__' :
48
+ LoggingTest ().main ()
0 commit comments