捕捉異常
# 使用logger.error來(lái)記錄錯(cuò)誤,也可以根據(jù)所需要的級(jí)別進(jìn)行修改
try:
? ? open('/somefile_not_exist','rb')
except Exception, e:
? ? logger.error('Failed to open file', exc_info=True)
這里:?
exc_info=True - 上報(bào)錯(cuò)誤并記錄錯(cuò)誤到log
exc_info=False - 不上報(bào)錯(cuò)誤,但記錄錯(cuò)誤到log
日志配置服務(wù)器
https://docs.python.org/zh-cn/3/howto/logging-cookbook.html#configuration-server-example
Qt GUI 日志示例
https://docs.python.org/zh-cn/3/howto/logging-cookbook.html#a-qt-gui-for-logging