summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Robertson <davidr@element.io>2021-08-19 13:35:38 +0100
committerDavid Robertson <davidr@element.io>2021-08-19 13:35:38 +0100
commit0dfd550e38b2bb3af30bd2d0e87e863d9fe55e68 (patch)
tree6abe5fe039d94a1c9677b2c21824b572b6066075
parentChangelog (diff)
downloadsynapse-github/dmr/log-exceptions-in-tests.tar.xz
I'm logging errors too. LoggingContextFilter. github/dmr/log-exceptions-in-tests dmr/log-exceptions-in-tests
-rw-r--r--changelog.d/10657.misc2
-rw-r--r--tests/test_utils/logging_setup.py16
2 files changed, 10 insertions, 8 deletions
diff --git a/changelog.d/10657.misc b/changelog.d/10657.misc
index dbc6d6d271..dfdfe51bda 100644
--- a/changelog.d/10657.misc
+++ b/changelog.d/10657.misc
@@ -1 +1 @@
-Log exceptions in tests to stderr.
\ No newline at end of file
+Log errors in tests to stderr.
\ No newline at end of file
diff --git a/tests/test_utils/logging_setup.py b/tests/test_utils/logging_setup.py
index a75a43bb03..debc8e24bb 100644
--- a/tests/test_utils/logging_setup.py
+++ b/tests/test_utils/logging_setup.py
@@ -36,7 +36,7 @@ class ToTwistedHandler(logging.Handler):
 def setup_logging():
     """Configure the python logging appropriately for the tests.
 
-    Logs will end up in _trial_temp. Exceptions are additionally
+    Logs will end up in _trial_temp. Errors are additionally
     logged to stderr.
     """
     root_logger = logging.getLogger()
@@ -45,17 +45,19 @@ def setup_logging():
         "%(asctime)s - %(name)s - %(lineno)d - "
         "%(levelname)s - %(request)s - %(message)s"
     )
+    formatter = logging.Formatter(log_format)
+    filter = LoggingContextFilter()
 
     to_twisted_handler = ToTwistedHandler()
-    formatter = logging.Formatter(log_format)
     to_twisted_handler.setFormatter(formatter)
-    to_twisted_handler.addFilter(LoggingContextFilter())
+    to_twisted_handler.addFilter(filter)
     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)
+    error_handler = logging.StreamHandler(sys.stderr)
+    error_handler.setLevel(logging.ERROR)
+    error_handler.setFormatter(formatter)
+    error_handler.addFilter(filter)
+    root_logger.addHandler(error_handler)
 
     log_level = os.environ.get("SYNAPSE_TEST_LOG_LEVEL", "ERROR")
     root_logger.setLevel(log_level)