如果您查看Python的源代码
logging/__init__.py,将会看到
basicConfig()通过调用设置了根logger对象上的处理程序
addHandler()。如果要从头开始,则可以删除所有现有的处理程序,然后
basicConfig()再次调用。
# 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')



