Skip to content

Commit 5a1a1b1

Browse files
jachiangPiRK
authored andcommitted
Add closing and flushing of logging handlers
Summary: > 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. This is a backport of Core [[bitcoin/bitcoin#17288 | PR17288]] [3/8] bitcoin/bitcoin@6f40820 Depends on D8242 Test Plan: `ninja && ninja check` Reviewers: O1 Bitcoin ABC, #bitcoin_abc, Fabien Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D8243
1 parent e80d5b9 commit 5a1a1b1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

test/functional/test_framework/test_framework.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,18 @@ def shutdown(self):
284284
self.log.error("Hint: Call {} '{}' to consolidate all logs".format(os.path.normpath(
285285
os.path.dirname(os.path.realpath(__file__)) + "/../combine_logs.py"), self.options.tmpdir))
286286
exit_code = TEST_EXIT_FAILED
287-
logging.shutdown()
287+
# Logging.shutdown will not remove stream- and filehandlers, so we must
288+
# do it explicitly. Handlers are removed so the next test run can apply
289+
# different log handler settings.
290+
# See: https://docs.python.org/3/library/logging.html#logging.shutdown
291+
for h in list(self.log.handlers):
292+
h.flush()
293+
h.close()
294+
self.log.removeHandler(h)
295+
rpc_logger = logging.getLogger("BitcoinRPC")
296+
for h in list(rpc_logger.handlers):
297+
h.flush()
298+
rpc_logger.removeHandler(h)
288299
if cleanup_tree_on_exit:
289300
shutil.rmtree(self.options.tmpdir)
290301
return exit_code

0 commit comments

Comments
 (0)