Log exception with traceback

后端 未结 11 1194
失恋的感觉
失恋的感觉 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 05:01

    maybe not as stylish, but easier:

    #!/bin/bash
    log="/var/log/yourlog"
    /path/to/your/script.py 2>&1 | (while read; do echo "$REPLY" >> $log; done)
    

提交回复
热议问题