使用标准 python logging api 在 pyqt4 应用程序中记录所有异常的最佳方法是什么?
我尝试将 exec_() 包装在 try, except 块中,并从中记录异常,但它仅记录应用程序初始化中的异常。
作为一个临时解决方案,我将最重要的方法封装在 try 中,除了块,但这不是唯一的方法。
你需要覆盖sys.excepthook
def my_excepthook(type, value, tback):
# log the exception here
# then call the default handler
sys.__excepthook__(type, value, tback)
sys.excepthook = my_excepthook