From 527a76e4e33a980c925315dc7700afcb060c365c Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Mon, 12 Jun 2017 18:05:31 -0400 Subject: do not add error_summary for debug log messages We catch exceptions and log debug messages a lot, which results in extra occurrences of the exception when we don't need them. Change-Id: I4dd3bf65fb456afc07a8fa7d0c9869bcc266b800 Related-Bug: #1696213 Related-Bug: #1696855 Signed-off-by: Doug Hellmann --- oslo_log/formatters.py | 5 +++++ oslo_log/tests/unit/test_log.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/oslo_log/formatters.py b/oslo_log/formatters.py index 2f9f979..c0da7eb 100644 --- a/oslo_log/formatters.py +++ b/oslo_log/formatters.py @@ -98,11 +98,16 @@ def _get_error_summary(record): If there is no active exception, return the default. + If the record is being logged at debug level, return an empty + string. + If there is an active exception, format it and return the resulting string. """ error_summary = '' + if record.levelno == logging.DEBUG: + return '' if record.exc_info: # Save the exception we were given so we can include the diff --git a/oslo_log/tests/unit/test_log.py b/oslo_log/tests/unit/test_log.py index a946d9e..9e860ab 100644 --- a/oslo_log/tests/unit/test_log.py +++ b/oslo_log/tests/unit/test_log.py @@ -577,7 +577,7 @@ class FluentFormatterTestCase(LogTestBase): try: raise RuntimeError('test_exception') except RuntimeError: - self.log.debug('testing', context=local_context) + self.log.info('testing', context=local_context) data = jsonutils.loads(self.stream.getvalue()) self.assertIn('error_summary', data) self.assertEqual('RuntimeError: test_exception', -- cgit v1.2.1