您可以删除默认处理程序并重新配置日志记录,如下所示:
# if someone tried to log something before basicConfig is called, Python creates a default handler that# goes to the console and will ignore further basicConfig calls. Remove the handler if there is one.root = logging.getLogger()if root.handlers: for handler in root.handlers: root.removeHandler(handler)logging.basicConfig(format='%(asctime)s %(message)s',level=logging.DEBUG)



