Skip to content

Commit 6f40820

Browse files
committed
Add closing and flushing of logging handlers
In order for BitcoinTestFramework to correctly restart after shutdown, the previous logging handlers need to be removed, or else logging will continue in the previous temp directory. "Flush" ensures buffers are emptied, and "close" ensures file handler close logging file.
1 parent 6b71241 commit 6f40820

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

test/functional/test_framework/test_framework.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,18 @@ def shutdown(self):
266266
self.log.error("Test failed. Test logging available at %s/test_framework.log", self.options.tmpdir)
267267
self.log.error("Hint: Call {} '{}' to consolidate all logs".format(os.path.normpath(os.path.dirname(os.path.realpath(__file__)) + "/../combine_logs.py"), self.options.tmpdir))
268268
exit_code = TEST_EXIT_FAILED
269-
logging.shutdown()
269+
# Logging.shutdown will not remove stream- and filehandlers, so we must
270+
# do it explicitly. Handlers are removed so the next test run can apply
271+
# different log handler settings.
272+
# See: https://docs.python.org/3/library/logging.html#logging.shutdown
273+
for h in list(self.log.handlers):
274+
h.flush()
275+
h.close()
276+
self.log.removeHandler(h)
277+
rpc_logger = logging.getLogger("BitcoinRPC")
278+
for h in list(rpc_logger.handlers):
279+
h.flush()
280+
rpc_logger.removeHandler(h)
270281
if cleanup_tree_on_exit:
271282
shutil.rmtree(self.options.tmpdir)
272283
return exit_code

0 commit comments

Comments
 (0)