diff options
author | David Robertson <davidr@element.io> | 2021-08-19 13:01:15 +0100 |
---|---|---|
committer | David Robertson <davidr@element.io> | 2021-08-19 13:06:52 +0100 |
commit | c0233eae5ee0c89357a4a5002eec7948ee88782c (patch) | |
tree | 67ac797757f69548fb938e5968b646fbf862affa | |
parent | Convert room member storage tuples to attrs. (#10629) (diff) | |
download | synapse-c0233eae5ee0c89357a4a5002eec7948ee88782c.tar.xz |
Log exceptions in tests to stderr
This makes it easy to see errors in background processes when you're writing unit tests. Otherwise, you have to know/remember to look at the test logs in `_trial_temp`.
-rw-r--r-- | tests/test_utils/logging_setup.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/tests/test_utils/logging_setup.py b/tests/test_utils/logging_setup.py index 51a197a8c6..a75a43bb03 100644 --- a/tests/test_utils/logging_setup.py +++ b/tests/test_utils/logging_setup.py @@ -13,6 +13,7 @@ # limitations under the License. import logging import os +import sys import twisted.logger @@ -35,7 +36,8 @@ class ToTwistedHandler(logging.Handler): def setup_logging(): """Configure the python logging appropriately for the tests. - (Logs will end up in _trial_temp.) + Logs will end up in _trial_temp. Exceptions are additionally + logged to stderr. """ root_logger = logging.getLogger() @@ -44,11 +46,16 @@ def setup_logging(): "%(levelname)s - %(request)s - %(message)s" ) - handler = ToTwistedHandler() + to_twisted_handler = ToTwistedHandler() formatter = logging.Formatter(log_format) - handler.setFormatter(formatter) - handler.addFilter(LoggingContextFilter()) - root_logger.addHandler(handler) + to_twisted_handler.setFormatter(formatter) + to_twisted_handler.addFilter(LoggingContextFilter()) + root_logger.addHandler(to_twisted_handler) + + exception_handler = logging.StreamHandler(sys.stderr) + exception_handler.setLevel(logging.ERROR) + exception_handler.setFormatter(formatter) + root_logger.addHandler(exception_handler) log_level = os.environ.get("SYNAPSE_TEST_LOG_LEVEL", "ERROR") root_logger.setLevel(log_level) |