python错误处理记录完整的异常堆栈信息,python错误堆栈信息,python的异常类中是
python错误处理记录完整的异常堆栈信息,python错误堆栈信息,python的异常类中是
python的异常类中是没有堆栈信息的,要记录堆栈最简单的办法是使用logging包,这包就是用来程序运行日志的。
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
这样logging.exception方法会自动记录异常信息,如下样例:
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
相关内容
- python使用深拷贝和浅拷贝复制对象,python拷贝,使用co
- easy_install 升级包,easy_install,easy_install
- easy_install 的n种用法,easy_install用法,easy_install
- python连接redis,pythonredis,首先需要通过easy_i
- python编写的FTP弱口令扫描器 python FTP暴力破解部分代码
- 把traceback信息传递给字符串,并且发送给邮箱,traceb
- python 生成java执行的shell文件,pythonshell,我有这么一个
- python自动投票测试,python投票测试,python伪造HTTP
- python Gevent multiprocessing server,,import sysfr
- python使用ssh连接远程服务器,并执行命令代码,python
评论关闭