summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-05-23 19:36:57 +0000
committerGerrit Code Review <review@openstack.org>2017-05-23 19:36:57 +0000
commit62e8c008ebc3382114dbc0ddc8c8b482cddcaf9b (patch)
treee8044d328b4d3eb68903a4537d67fe76ae25bafb
parentda55f6ff1f747fe5dd334b44f0b154f514595e7e (diff)
parentc06db3c1d193fba6254e675c43a24b0843ed30d0 (diff)
downloadoslo-log-62e8c008ebc3382114dbc0ddc8c8b482cddcaf9b.tar.gz
Merge "add error_summary support to JSONFormatter"
-rw-r--r--oslo_log/formatters.py3
-rw-r--r--oslo_log/tests/unit/test_log.py20
2 files changed, 22 insertions, 1 deletions
diff --git a/oslo_log/formatters.py b/oslo_log/formatters.py
index 3355352..e95d508 100644
--- a/oslo_log/formatters.py
+++ b/oslo_log/formatters.py
@@ -193,7 +193,8 @@ class JSONFormatter(logging.Formatter):
'process_name': record.processName,
'process': record.process,
'traceback': None,
- 'hostname': self.hostname}
+ 'hostname': self.hostname,
+ 'error_summary': _get_error_summary(record)}
# Build the extra values that were given to us, including
# the context.
diff --git a/oslo_log/tests/unit/test_log.py b/oslo_log/tests/unit/test_log.py
index acf6f95..ab1950c 100644
--- a/oslo_log/tests/unit/test_log.py
+++ b/oslo_log/tests/unit/test_log.py
@@ -497,6 +497,26 @@ class JSONFormatterTestCase(LogTestBase):
self.log.info(b'%s', u'\u2622'.encode('utf8'))
self.assertIn(expected, self.stream.getvalue())
+ def test_exception(self):
+ ctxt = _fake_context()
+ ctxt.request_id = six.text_type('99')
+ try:
+ raise RuntimeError('test_exception')
+ except RuntimeError:
+ self.log.info('testing', context=ctxt)
+ data = jsonutils.loads(self.stream.getvalue())
+ self.assertIn('error_summary', data)
+ self.assertEqual('RuntimeError: test_exception',
+ data['error_summary'])
+
+ def test_no_exception(self):
+ ctxt = _fake_context()
+ ctxt.request_id = six.text_type('99')
+ self.log.info('testing', context=ctxt)
+ data = jsonutils.loads(self.stream.getvalue())
+ self.assertIn('error_summary', data)
+ self.assertEqual('', data['error_summary'])
+
def get_fake_datetime(retval):
class FakeDateTime(datetime.datetime):