Log exception with traceback

后端 未结 11 1182
失恋的感觉
失恋的感觉 2020-12-02 04:25

How can I log my Python errors?

try:
    do_something()
except:
    # How can I log my exception here, complete with its traceback?
11条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 04:56

    Use exc_info options may be better, remains warning or error title:

    try:
        # coode in here
    except Exception as e:
        logging.error(e, exc_info=True)
    

提交回复
热议问题