Пример #1
0
def test_create_console_log_handler(capsys):

    debug_test_string = 'debug_create_console_test_string'
    info_test_string = 'info_create_console_test_string'

    # Default handler
    handler = create_console_log_handler()
    assert isinstance(handler, logging.StreamHandler)
    assert isinstance(handler.formatter, _DefaultConsoleFormat)
    assert handler.level == logging.DEBUG

    logger = create_logger(handlers=[handler])

    logger.info(info_test_string)
    logger.debug(debug_test_string)
    _, err = capsys.readouterr()

    assert '[DEBUG]> {test_string}'.format(
        test_string=debug_test_string) in err
    assert err.count(info_test_string) == 1

    # Custom handler
    custom_handler = create_console_log_handler(level=logging.INFO,
                                                formatter=logging.Formatter())
    assert isinstance(custom_handler.formatter, logging.Formatter)
    assert custom_handler.level == logging.INFO

    logger = create_logger(handlers=[custom_handler])

    logger.info(info_test_string)
    _, err = capsys.readouterr()

    assert err.count(info_test_string) == 1
Пример #2
0
def main():
    create_logger(handlers=[
        create_console_log_handler(),
        create_file_log_handler(file_path='/tmp/aria_cli.log'),
    ],
                  level=logging.INFO)
    with AriaCli() as aria:
        aria.run()
Пример #3
0
def test_loggermixin(capsys):

    test_string = 'loggermixing_test_string'

    create_logger(handlers=[create_console_log_handler()])

    custom_class = type('CustomClass', (LoggerMixin, ), {}).with_logger()
    custom_class.logger.debug(test_string)

    _, err = capsys.readouterr()
    assert test_string in err