I would like to log all warnings. I thought that setting captureWarnings
to True
should do the trick, but it doesn't. Code:
import logging
import warnings
from logging.handlers import RotatingFileHandler
logger_file_handler = RotatingFileHandler(u'./test.log')
logger_file_handler.setLevel(logging.DEBUG)
logging.captureWarnings(True)
logger = logging.getLogger(__name__)
logger.addHandler(logger_file_handler)
logger.setLevel(logging.DEBUG)
logger.info(u'Test')
warnings.warn(u'Warning test')
My expectation is that 'Warning test' should appear in test.log, but it doesn't; only 'Test' is put in the log file.
How to capture all warnings and redirect them to the log file?