Ejemplo n.º 1
0
def test_file_logging_rotation(logger, tmpdir):
    """Test Depot ID TBD.

    Test that log content ends up in a file when set a logdir.
    """
    # Rotate log file every 20 bytes
    log_config = LoggingConfig(ignore_env=True,
                               **{
                                   'log_directory': str(tmpdir),
                                   'file_rotation_max_bytes': 20,
                                   'file_rotation_backup_count': 2
                               })
    setup_file_logging(log_config, 'log_file')

    # These two lines are greater than file_rotation_max_bytes, so first message should get rotated
    message1 = 'test_file_logging_part1'
    message2 = 'test_file_logging_part2'

    # Log error message, should go into log_file.log
    logger.error(message1)
    logger.error(message2)

    expected_filename1 = os.path.join(str(tmpdir), 'log_file.log')
    with open(expected_filename1, 'r') as f:
        assert message2 in f.read()
        assert message1 not in f.read()

    expected_filename2 = os.path.join(str(tmpdir), 'log_file.log.1')
    with open(expected_filename2, 'r') as f:
        assert message1 in f.read()
        assert message2 not in f.read()
Ejemplo n.º 2
0
def test_file_logging_prefix(logger, tmpdir):
    """Test Depot ID TBD.

    Test that file_prefix works in logging config
    """
    log_config = LoggingConfig(ignore_env=True, **{'log_directory': str(tmpdir), 'file_prefix': 'foo'})
    setup_file_logging(log_config, 'log_file')
    message = 'test_file_logging'
    logger.error(message)
    expected_filename = os.path.join(str(tmpdir), 'foo_log_file.log')
    with open(expected_filename, 'r') as f:
        assert message in f.read()
Ejemplo n.º 3
0
def test_file_logging(logger, tmpdir):
    """Test Depot ID TBD.

    Test that log content ends up in a file when set a logdir.
    """
    log_config = LoggingConfig(ignore_env=True, **{'log_directory': str(tmpdir)})
    setup_file_logging(log_config, 'log_file')
    message = 'test_file_logging'
    logger.error(message)
    expected_filename = os.path.join(str(tmpdir), 'log_file.log')
    with open(expected_filename, 'r') as f:
        assert message in f.read()
Ejemplo n.º 4
0
def test_scrubbed_logs(logger):
    """Test Depot ID TBD.

    Verify if sensitive messages are getting scrubbed.
    """
    config = LoggingConfig(ignore_env=True, **{'enable_scrubbing': True})
    configure_logging(config)
    for msg in ['123456789', '123445677888', '11aa123456789a']:
        logger.info(msg)
        assert '<<SCRUBBED>>' in logger_stream_contents(logger)
        # Clear the stream after each iteration so we have clean stream
        logger_stream_reset(logger)

        # Also check the same thing works for a child logger
        logging.getLogger('dirbs.import').info(msg)
        assert '<<SCRUBBED>>' in logger_stream_contents(logger)
        logger_stream_reset(logger)