If you look in the Python sources for logging/__init__.py
, you’ll see that basicConfig()
sets the handlers on the root logger object by calling addHandler()
. If you want to start from scratch, you could remove all existing handlers and then call basicConfig()
again.
# Example to remove all root logger handlers and reconfigure. (UNTESTED)
import logging
# Remove all handlers associated with the root logger object.
for handler in logging.root.handlers[:]:
logging.root.removeHandler(handler)
# Reconfigure logging again, this time with a file.
logging.basicConfig(filename="myfile.log", level=logging.DEBUG, format="%(filename)s:%(lineno)s %(levelname)s:%(message)s")