Add a null handler to the root logger to silence test errors

This commit is contained in:
Jake Moshenko 2016-01-28 11:30:47 -05:00
parent eaa89bc61e
commit 8c82fb44ae

7
app.py
View file

@ -104,8 +104,13 @@ class InjectingFilter(logging.Filter):
record.msg = '[%s] %s' % (request.request_id, record.msg) record.msg = '[%s] %s' % (request.request_id, record.msg)
return True return True
root_logger = logging.getLogger()
# Add a null handler to the root logger to silence missing handler errors in tests
root_logger.addHandler(logging.NullHandler())
# Add the request id filter to all handlers of the root logger # Add the request id filter to all handlers of the root logger
for handler in logging.getLogger().handlers: for handler in root_logger.handlers:
handler.addFilter(InjectingFilter()) handler.addFilter(InjectingFilter())
app.request_class = RequestWithId app.request_class = RequestWithId