enable isotime for exceptions

Change Id4754c18935940cc7c738e4a91880267fdeb808f only added isotime to
the formatting for regular log messages, and not exceptions. This change
adds support for the isotime variable in the log prefix string for
tracebacks.

Change-Id: I7203839a2366692e7d54597eacadb17ee24a1f0a
This commit is contained in:
Doug Hellmann
2016-01-04 21:24:22 +00:00
parent 648e2f5a6a
commit 149041df41
2 changed files with 44 additions and 13 deletions

View File

@@ -528,6 +528,32 @@ class ExceptionLoggingTestCase(LogTestBase):
log.setup(self.CONF, "test_excepthook_installed")
self.assertTrue(sys.excepthook != sys.__excepthook__)
@mock.patch("datetime.datetime",
get_fake_datetime(
datetime.datetime(2015, 12, 16, 13, 54, 26, 517893)))
@mock.patch("dateutil.tz.tzlocal", new=mock.Mock(return_value=tz.tzutc()))
def test_rfc5424_isotime_format(self):
self.config(
logging_default_format_string="%(isotime)s %(message)s",
logging_exception_prefix="%(isotime)s ",
)
product_name = 'somename'
exc_log = log.getLogger(product_name)
self._add_handler_with_cleanup(exc_log)
excepthook = log._create_logging_excepthook(product_name)
try:
raise Exception('Some error happened')
except Exception:
excepthook(*sys.exc_info())
expected_string = ("2015-12-16T13:54:26.517893+00:00 "
"Exception: Some error happened")
self.assertIn(expected_string,
self.stream.getvalue())
class FancyRecordTestCase(LogTestBase):
"""Test how we handle fancy record keys that are not in the