带回溯的日志异常

带回溯的日志异常,第1张

回溯日志异常

logging.exception
except:
处理程序/块中使用,可将当前异常与跟踪信息一起记录在日志中,并附带一条消息。

import loggingLOG_FILENAME = '/tmp/logging_example.out'logging.basicConfig(filename=LOG_FILENAME, level=logging.DEBUG)logging.debug('This message should go to the log file')try:    run_my_stuff()except:    logging.exception('Got exception on main handler')    raise

现在查看日志文件

/tmp/logging_example.out

DEBUG:root:This message should go to the log fileERROR:root:Got exception on main handlerTraceback (most recent call last):  File "/tmp/teste.py", line 9, in <module>    run_my_stuff()NameError: name 'run_my_stuff' is not defined


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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存