def test_handler(self):
     handler = handlers.OSSysLogHandler()
     syslog.syslog = mock.Mock()
     handler.emit(
         logging.LogRecord("foo", logging.INFO, "path", 123, "hey!", None,
                           None))
     self.assertTrue(syslog.syslog.called)
 def test_syslog_binary_name(self):
     # There is no way to test the actual output written to the
     # syslog (e.g. /var/log/syslog) to confirm binary_name value
     # is actually present
     syslog.openlog = mock.Mock()
     handlers.OSSysLogHandler()
     syslog.openlog.assert_called_with(handlers._get_binary_name(), 0,
                                       syslog.LOG_USER)
Exemple #3
0
def setup_logging():
    log_file = cfg.CONF.network_log.local_output_log_base
    if log_file:
        from logging import handlers as watch_handler
        log_file_handler = watch_handler.WatchedFileHandler(log_file)
        LOG.logger.addHandler(log_file_handler)
    elif cfg.CONF.use_journal:
        journal_handler = handlers.OSJournalHandler()
        LOG.logger.addHandler(journal_handler)
    else:
        syslog_handler = handlers.OSSysLogHandler()
        LOG.logger.addHandler(syslog_handler)
Exemple #4
0
def setup_logging():

    log_file = cfg.CONF.network_log.local_output_log_base
    if log_file:
        import logging
        log_file_handler = logging.handlers.WatchedFileHandler(log_file)
        log_file_handler.setLevel(logging.INFO)
        log_file_handler.setFormatter(
            logging.Formatter(fmt="%(asctime)s %(message)s",
                              datefmt=cfg.CONF.log_date_format))
        LOG.logger.addHandler(log_file_handler)
    elif cfg.CONF.use_journal:
        journal_handler = handlers.OSJournalHandler()
        LOG.logger.addHandler(journal_handler)
    else:
        syslog_handler = handlers.OSSysLogHandler()
        LOG.logger.addHandler(syslog_handler)
Exemple #5
0
def setup_logging():
    log_file = cfg.CONF.network_log.local_output_log_base
    if log_file:
        from logging import handlers as watch_handler
        log_file_handler = watch_handler.WatchedFileHandler(log_file)
        log_file_handler.setLevel(
            logging.DEBUG if cfg.CONF.debug else logging.INFO)
        LOG.logger.addHandler(log_file_handler)
        log_file_handler.setFormatter(
            formatters.ContextFormatter(
                fmt=cfg.CONF.logging_default_format_string,
                datefmt=cfg.CONF.log_date_format))
    elif cfg.CONF.use_journal:
        journal_handler = handlers.OSJournalHandler()
        LOG.logger.addHandler(journal_handler)
    else:
        syslog_handler = handlers.OSSysLogHandler()
        LOG.logger.addHandler(syslog_handler)