我想暂时让logging.warning
次调用引发异常,而不是打印并继续。我怎么能这样做?
import logging
logging.warning("Foo") # Should raise exception
logging.info("Bar") # Should not raise exception
答案 0 :(得分:0)
当您启动日志记录更改警告调用时
def warning(self, message, *args, **kws):
if self.isEnabledFor(logging.WARNING):
self._log(logging.WARNING, message, args, **kws)
raise Exception(message)
logging.Logger.warning = warning