更改已设置的日志记录的“ basicConfig”

更改已设置的日志记录的“ basicConfig”,第1张

更改已设置的日志记录的“ basicConfig”

如果您查看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')


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5648072.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存