import side effects on logging: how to reset the logging module?
It depends on what the other module is doing; e.g. if it's calling logging.disable
then you can call logging.disable(logging.NOTSET)
to reset it.
You could try reloading the logging
module:
from importlib import reload
logging.shutdown()
reload(logging)
The problem is this will leave the third-party module with its own copy of logging
in an unusable state, so could cause more problems later.
To completely clear existing logging configuration from the root logger, this might work:
root = logging.getLogger()
list(map(root.removeHandler, root.handlers))
list(map(root.removeFilter, root.filters))
However, this doesn't reset to the "default", this clears everything. You'd have to then add a StreamHandler
to achieve what you want.