summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-05-21 16:07:30 +0000
committerGerrit Code Review <review@openstack.org>2017-05-21 16:07:31 +0000
commit49422ab97fe8dac280b3f240f7325380f37ac7d1 (patch)
tree37848b7e299d8fe3f2a22aff8c2dff3a401567c6
parent8252df5927471251dec5c323e78d59b1e3046330 (diff)
parent0caffbd0db2f83c7c632884abaade0aa96a7321e (diff)
downloadoslo-log-49422ab97fe8dac280b3f240f7325380f37ac7d1.tar.gz
Merge "skip built-in exceptions when adding error_summary"
-rw-r--r--oslo_log/formatters.py11
-rw-r--r--oslo_log/tests/unit/test_log.py15
2 files changed, 26 insertions, 0 deletions
diff --git a/oslo_log/formatters.py b/oslo_log/formatters.py
index e6faebc..fc1bc51 100644
--- a/oslo_log/formatters.py
+++ b/oslo_log/formatters.py
@@ -363,6 +363,17 @@ class ContextFormatter(logging.Formatter):
# that uses the value simpler.
if not exc_info[0]:
exc_info = None
+ elif exc_info[0] in (TypeError, ValueError,
+ KeyError, AttributeError):
+ # NOTE(dhellmann): Do not include information about
+ # common built-in exceptions used to detect cases of
+ # bad or missing data. We don't use isinstance() here
+ # to limit this filter to only the built-in
+ # classes. This check is only performed for cases
+ # where the exception info is being detected
+ # automatically so if a caller gives us an exception
+ # we will definitely log it.
+ exc_info = None
# If we have an exception, format it to be included in the
# output.
diff --git a/oslo_log/tests/unit/test_log.py b/oslo_log/tests/unit/test_log.py
index a4405de..acf6f95 100644
--- a/oslo_log/tests/unit/test_log.py
+++ b/oslo_log/tests/unit/test_log.py
@@ -657,6 +657,21 @@ class ContextFormatterTestCase(LogTestBase):
expected = 'RuntimeError: test_exception_logging\n'
self.assertTrue(self.stream.getvalue().endswith(expected))
+ def test_skip_logging_builtin_exceptions(self):
+ # NOTE(dhellmann): If there is an exception and %(error_summary)s
+ # does not appear in the format string, ensure that it is
+ # appended to the end of the log lines.
+ ctxt = _fake_context()
+ ctxt.request_id = six.text_type('99')
+ message = self.trans_fixture.lazy('test ' + six.unichr(128))
+ for ignore in [ValueError, TypeError, KeyError, AttributeError]:
+ try:
+ raise ignore('test_exception_logging')
+ except ignore as e:
+ self.log.info(message, context=ctxt)
+ expected = '{}: {}'.format(e.__class__.__name__, e)
+ self.assertNotIn(expected, self.stream.getvalue())
+
def test_exception_logging_format_string(self):
# NOTE(dhellmann): If the format string includes
# %(error_summary)s then ensure the exception message ends up in