使用标准python logging api记录pyqt4应用程序中所有异常的最佳方法是什么?

我尝试将tryc_()包装在try(块除外)中,并记录异常,但它只记录应用程序初始化中的异常。

作为一个临时解决方案,我在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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top