Пример #1
0
        def test_logging(self):
                global_settings.client_name = "TestSettings"

                info_out = six.StringIO()
                error_out = six.StringIO()

                log_fmt = logging.Formatter()

                # Enforce maximum logging level for informational messages.
                info_h = logging.StreamHandler(info_out)
                info_t = _LogFilter(logging.INFO)
                info_h.addFilter(info_t)
                info_h.setFormatter(log_fmt)
                info_h.setLevel(logging.INFO)

                # Log all warnings and above to stderr.
                error_h = logging.StreamHandler(error_out)
                error_h.setFormatter(log_fmt)
                error_h.setLevel(logging.WARNING)

                global_settings.info_log_handler = info_h
                global_settings.error_log_handler = error_h

                # Log some messages.
                logger.debug("DEBUG")
                logger.info("INFO")
                logger.warning("WARNING")
                logger.error("ERROR")
                logger.critical("CRITICAL")

                # Now verify that the expected output was received (DEBUG
                # shouldn't be here due to log level).
                self.assertEqual(info_out.getvalue(), "INFO\n")
                self.assertEqual(error_out.getvalue(),
                    "WARNING\nERROR\nCRITICAL\n")

                # DEBUG should now be present in the info output.
                info_out.seek(0)
                info_h.setLevel(logging.DEBUG)
                logger.debug("DEBUG")
                self.assertEqual(info_out.getvalue(), "DEBUG\n")

                # Reset logging and verify info_out, error_out are no longer
                # set to receive messagse.
                global_settings.reset_logging()
                self.assertNotEqual(global_settings.info_log_handler, info_h)
                self.assertNotEqual(global_settings.error_log_handler, error_h)

                logging.shutdown()
Пример #2
0
        def test_logging(self):
                global_settings.client_name = "TestSettings"

                info_out = StringIO.StringIO()
                error_out = StringIO.StringIO()

                log_fmt = logging.Formatter()

                # Enforce maximum logging level for informational messages.
                info_h = logging.StreamHandler(info_out)
                info_t = _LogFilter(logging.INFO)
                info_h.addFilter(info_t)
                info_h.setFormatter(log_fmt)
                info_h.setLevel(logging.INFO)

                # Log all warnings and above to stderr.
                error_h = logging.StreamHandler(error_out)
                error_h.setFormatter(log_fmt)
                error_h.setLevel(logging.WARNING)

                global_settings.info_log_handler = info_h
                global_settings.error_log_handler = error_h

                # Log some messages.
                logger.debug("DEBUG")
                logger.info("INFO")
                logger.warning("WARNING")
                logger.error("ERROR")
                logger.critical("CRITICAL")

                # Now verify that the expected output was received (DEBUG
                # shouldn't be here due to log level).
                self.assertEqual(info_out.getvalue(), "INFO\n")
                self.assertEqual(error_out.getvalue(),
                    "WARNING\nERROR\nCRITICAL\n")

                # DEBUG should now be present in the info output.
                info_out.truncate(0)
                info_h.setLevel(logging.DEBUG)
                logger.debug("DEBUG")
                self.assertEqual(info_out.getvalue(), "DEBUG\n")

                # Reset logging and verify info_out, error_out are no longer
                # set to receive messagse.
                global_settings.reset_logging()
                self.assertNotEqual(global_settings.info_log_handler, info_h)
                self.assertNotEqual(global_settings.error_log_handler, error_h)

                logging.shutdown()
Пример #3
0
def shutdown_logging():
        try:
                global_settings.reset_logging()
                logging.shutdown()
        except IOError:
                pass