def test_log_format_overrides_formatter(self): self.CONF(['--log-format', '[Any format]']) log._setup_logging_from_conf('test', 'test') logger = log._loggers[None].logger for handler in logger.handlers: formatter = handler.formatter self.assertTrue(isinstance(formatter, logging.Formatter))
def test_log_dir_handlers(self): log_dir = tempfile.mkdtemp() self.CONF(['--log-dir', log_dir]) self.CONF.set_default('use_stderr', False) log._setup_logging_from_conf('test', 'test') logger = log._loggers[None].logger self.assertEqual(1, len(logger.handlers)) self.assertIsInstance(logger.handlers[0], logging.handlers.WatchedFileHandler)
def setUp(self): super(CommonLoggerTestsMixIn, self).setUp() self.config = self.useFixture(config.Config()).config # common context has different fields to the defaults in log.py self.config(logging_context_format_string='%(asctime)s %(levelname)s ' '%(name)s [%(request_id)s ' '%(user)s %(tenant)s] ' '%(message)s') self.log = None log._setup_logging_from_conf('test', 'test')
def test_default_formatter(self): log._setup_logging_from_conf('test', 'test') logger = log._loggers[None].logger for handler in logger.handlers: formatter = handler.formatter self.assertTrue(isinstance(formatter, log.ContextFormatter))