Exemple #1
0
def test_make_record_context_extra():
    Context.new()
    logger = logs.StructuredLogger('test')
    logs.logging_context.push(a=1)
    record = logger.makeRecord(*record_args())
    assert record.__dict__['a'] == 1
    assert record._structured == {'a': 1}
Exemple #2
0
def test_make_record_context_renamed():
    Context.new()
    logger = logs.StructuredLogger('test')
    logs.set_global_extra({'a': 1})
    logs.logging_context.push(a=2)
    record = logger.makeRecord(*record_args())
    assert record._structured == {'a': 1, 'a_': 2}
Exemple #3
0
def test_make_record_global_extra():
    Context.new()
    logger = logs.StructuredLogger('test')
    logs.set_global_extra({'a': 1})
    record = logger.makeRecord(*record_args())
    assert record.__dict__['a'] == 1
    assert record._structured == {'a': 1}
Exemple #4
0
def make_record(extra, msg='msg here'):
    """Make a test record from StructuredLogger."""
    logger = logs.StructuredLogger('test')
    record = logger.makeRecord(*record_args(msg), extra=extra)
    # stub out the time
    record.__dict__['created'] = TIME
    record.msecs = MSEC
    return record
Exemple #5
0
def test_make_record_context_overiddes():
    logger = logs.StructuredLogger('test')
    logger.update_extra({'a': 1})
    logs.set_logging_context(a=2)
    record = logger.makeRecord(*record_args())

    assert record.__dict__['a'] == 2
    assert record._structured == {'a': 2}
Exemple #6
0
def test_make_record_all_extra():
    logger = logs.StructuredLogger('test')
    logger.update_extra({'a': 1})
    logs.set_logging_context(b=2)
    record = logger.makeRecord(*record_args(), extra={'c': 3})

    assert record.__dict__['a'] == 1
    assert record.__dict__['b'] == 2
    assert record.__dict__['c'] == 3
    assert record._structured == {'a': 1, 'b': 2, 'c': 3}
Exemple #7
0
def test_make_record_protected(monkeypatch):
    def error(*args):
        raise Exception()

    monkeypatch.setattr(logs.logging_context, 'get', error)
    logger = logs.StructuredLogger('test')
    record = logger.makeRecord(*record_args('test'), extra={'foo': 'bar'})
    assert record.foo == 'bar'
    assert record.extra == {'foo': 'bar'}
    assert record._trailer is None
Exemple #8
0
def test_make_record_ordering():
    logger = logs.StructuredLogger('test')
    logs.set_global_extra({'global': 1})
    logs.logging_context.push(context=2)
    extra = OrderedDict()
    extra['user1'] = 3
    extra['user2'] = 4
    record = logger.makeRecord(*record_args(), extra=extra)
    assert list(
        record._structured.keys()) == ['user1', 'user2', 'context', 'global']
Exemple #9
0
def test_logger_collects_raven_breadcrumbs():
    logger = logs.StructuredLogger('test')
    with raven.context.Context() as ctx:
        logger.info('info', extra={'foo': 'bar'})
        logger.debug('debug', extra={'foo': 'bar'})
        breadcrumbs = ctx.breadcrumbs.get_buffer()

    assert len(breadcrumbs) == 1
    assert breadcrumbs[0]['message'] == 'info'
    assert breadcrumbs[0]['level'] == 'info'
    assert breadcrumbs[0]['category'] == 'test'
    assert breadcrumbs[0]['data'] == {'extra': {'foo': 'bar'}}
Exemple #10
0
def test_make_record_no_extra():
    logger = logs.StructuredLogger('test')
    record = logger.makeRecord(*record_args())
    assert record._structured == {}
Exemple #11
0
def test_make_record_extra_renamed():
    logger = logs.StructuredLogger('test')
    logs.set_global_extra({'a': 1})
    record = logger.makeRecord(*record_args(), extra={'a': 2})
    assert record._structured == {'a': 1, 'a_': 2}
Exemple #12
0
def test_make_record_context_renamed():
    logger = logs.StructuredLogger('test')
    logger.update_extra({'a': 1})
    logs.set_logging_context(a=2)
    record = logger.makeRecord(*record_args())
    assert record._structured == {'a': 1, 'a_': 2}