python日志记录不会捕获异常

时间:2013-06-07 08:18:43

标签: python exception logging websocket

当我尝试使用python的日志记录模块时,它似乎捕获异常并打印出错误,而不是让程序正常崩溃。

要初始化日志,我有这个:

logging.basicConfig(level=logging.DEBUG)

现在我收到了所有的信息和警告消息,但除此之外,当出现错误时,它会被捕获并打印为“错误”日志消息:

ERROR:root:'bool' object is not iterable

这导致了我的两个问题:

  1. 我看不到堆栈跟踪。
  2. 程序继续执行。
  3. 有没有办法禁用此行为,以便程序崩溃堆栈跟踪,就像我没有启用日志记录一样?

    修改

    我是个白痴。抓住异常并不是日志记录。这是websocket-client模块。更具体地说,这些行:

         except Exception, e:
            self._run_with_no_err(self.on_error, e)
    
    def _run_with_no_err(self, callback, *args):
        if callback:
            try:
                callback(self, *args)
            except Exception, e:
                if logger.isEnabledFor(logging.DEBUG):
                    logger.error(e)
    

    当我启用日志记录时,我注意到了这种行为,并且认为两者没有连接。

0 个答案:

没有答案
相关问题