Пример #1
0
    def test_cant_open_stream(self, log_directory, capsys):
        log_dir = os.path.join(log_directory, 'non_existent_directory')
        with staticconf.testing.MockConfiguration(log_dir=log_dir, namespace='clog'):
            logger = FileLogger()
            stream = 'first'
            with pytest.raises(IOError):
                logger.log_line(stream, first_line)

            stdout, stderr = capsys.readouterr()
            assert stderr == 'Unable to open file for stream first in directory {0}\n'.format(
                log_dir
            )
Пример #2
0
    def test_cant_open_stream(self, log_directory, capsys):
        log_dir = os.path.join(log_directory, 'non_existent_directory')
        with staticconf.testing.MockConfiguration(log_dir=log_dir,
                                                  namespace='clog'):
            logger = FileLogger()
            stream = 'first'
            with pytest.raises(IOError):
                logger.log_line(stream, first_line)

            stdout, stderr = capsys.readouterr()
            assert stderr == 'Unable to open file for stream first in directory {0}\n'.format(
                log_dir)
Пример #3
0
def check_create_default_loggers():
    """Set up global loggers, if necessary."""
    global loggers

    # important to specifically compare to None, since empty list means something different
    if loggers is None:

        # initialize list of loggers
        loggers = []

        # possibly add logger that writes to local files (for dev)
        if config.clog_enable_file_logging:
            if config.log_dir is None:
                raise ValueError(
                    'log_dir not set; set it or disable clog_enable_file_logging'
                )
            loggers.append(FileLogger())

        # possibly add logger that writes to scribe
        if not config.scribe_disable:
            logger = ScribeLogger(config.scribe_host, config.scribe_port,
                                  config.scribe_retry_interval)
            loggers.append(logger)

        if config.clog_enable_stdout_logging:
            loggers.append(StdoutLogger())

        if not loggers and not config.is_logging_configured:
            raise LoggingNotConfiguredError
Пример #4
0
    def test_log_line(self, log_directory, line1, expected_output):
        logger = FileLogger()
        stream = 'file_logger_stream'
        logger.log_line(stream, line1)
        logger.log_line(stream, 'world')
        logger.close()

        assert self._open_and_remove(
            logger.stream_files[stream].name) == expected_output
Пример #5
0
    def test_log_line(self, log_directory, line1, expected_output):
        logger = FileLogger()
        stream = 'file_logger_stream'
        logger.log_line(stream, line1)
        logger.log_line(stream, 'world')
        logger.close()

        assert self._open_and_remove(logger.stream_files[stream].name) == expected_output