def test_excepthook_logs_exception(self): 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 = ("CRITICAL somename [-] " "Exception: Some error happened") self.assertTrue(expected_string in self.stream.getvalue(), msg="Exception is not logged")
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())