Exemple #1
0
def test_exception_handler(logger):
    from logbook.more import ExceptionHandler

    with ExceptionHandler(ValueError):
        with pytest.raises(ValueError) as caught:
            logger.info('here i am')
    assert 'INFO: testlogger: here i am' in caught.value.args[0]
Exemple #2
0
def test_exception_handler_specific_level(logger):
    from logbook.more import ExceptionHandler
    with logbook.TestHandler() as test_handler:
        with pytest.raises(ValueError) as caught:
            with ExceptionHandler(ValueError, level='WARNING'):
                logger.info('this is irrelevant')
                logger.warn('here i am')
        assert 'WARNING: testlogger: here i am' in caught.value.args[0]
    assert 'this is irrelevant' in test_handler.records[0].message
Exemple #3
0
    """Get a logger with handlers attached."""
    l = logbook.Logger(name)
    for h in handlers:
        if isinstance(h, list):
            l.handlers = h
        else:
            l.handlers = [h]
    return l


STDERR_HANDLER = [ColorfulStderrHandler(
    level=logbook.INFO if not DEBUG else logbook.DEBUG,
    format_string=u'[{record.time:%Y-%m-%dT%H:%M:%SZ}] {record.level_name}: {record.channel}: {record.message}'
)]
LOGGER = get_logger('Nikola', STDERR_HANDLER)
STRICT_HANDLER = ExceptionHandler(ApplicationWarning, level='WARNING')

# This will block out the default handler and will hide all unwanted
# messages, properly.
logbook.NullHandler().push_application()

if DEBUG:
    logging.basicConfig(level=logging.DEBUG)
else:
    logging.basicConfig(level=logging.INFO)


import warnings


def showwarning(message, category, filename, lineno, file=None, line=None):