This is a WIP PR. Comments and feedback on the overall approach welcomed!
(For an overview of python’s logging module and terms, see https://docs.python.org/3/library/logging.html and https://docs.python.org/3/howto/logging.html)
This PR adds logging to the test-framwork.py module. The “TestFramework” logger is added as a member of the BitcoinTestFramework class, and two handlers are attached to the logger:
- a StreamHandler() which outputs ERROR and higher level records to stderr.
- a FileHandler() which outputs all log records to a new
test_framework.log
file in the temporary test directory.
Test scripts and helper modules can log to the same Logger so there’s a single log output:
- Individual test scripts can log to “TestFramework” by calling
self.log.[debug|info|warning|error|critical|exception]()
. - Helper modules should log to child Loggers such as “TestFramework.mininode” or “TestFramework.authproxy”, which will result in log records being propagated up to the “TestFramework” Logger.
I’ve added examples of how individual scripts and helper modules should log events in p2p-segwit.py and mininode.py.
The eventual goal is to remove all print()
calls and replace them with logging.
A few notes on the implementation:
- a new
--loglevel
parameter can be used to log lower level records to the console, for example--loglevel=DEBUG
will emit all log records to the console. - the date format of
test_framework.log
is the same as bitcoind’s debug.log. It should be trivial to interleavetest_framework.log
with the variousnodeX/debug.log
files for a global view of what’s happening during the test. - this should have no interaction with the existing
--tracerpc
parameter