add error_summary support to JSONFormatter
Change-Id: I177a9f1a127da8d7cbb4da5bccc315b5a7dbaaba Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
b9f339eef2
commit
c06db3c1d1
|
@ -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.
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue