diff --git a/oslo_log/formatters.py b/oslo_log/formatters.py index 33553528..e95d5082 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 acf6f95a..ab1950c8 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):