我试图在我的代码中具有以下功能:
develop = True目前,我正在使用 Python3logging模块,它(根据this)应该具有内置的功能。标志是logging.raiseExceptions = True。
但是,我没有让它在 MWE 中工作:无论我的标志设置是什么,我抛出的异常都不会重新引发。
# mwe.py
import logging
import logging.config
if __name__ == '__main__':
# Configure logging and set flag to raise exceptions
logging.config.fileConfig('log.conf')
logging.raiseExceptions = True
logger = logging.getLogger('root')
logger.info('Started')
# Test whether exceptions get raised
try:
raise RuntimeError("Ooops.")
except RuntimeError:
try:
logger.exception('There was an oops.')
# which is the same as logger.error('...', exc_info=True)
except:
print("GOTCHA! Exception was re-raised.")
logger.info('Finished') …Run Code Online (Sandbox Code Playgroud)