コード例 #1
0
def test_manual_injection():
    tagged_logger.add_tagging_attrs(ta(user="******"), ip="127.0.0.1")
    tagged_logger.log("{user} is from {ip}")
    tagged_logger.rm_tagging_attrs(ta(user="******"), ip="127.0.0.1")
    tagged_logger.log("random message")
    record = tagged_logger.get_latest(user="******")
    assert set(record.tags) == set(["user:foo", "ip:127.0.0.1"])
    assert record.attrs == {"user": "******", "ip": "127.0.0.1"}
コード例 #2
0
def test_context():
    with tagged_logger.context(ta(user="******", ip="127.0.0.1")):
        tagged_logger.log("{user} is from {ip}")
    tagged_logger.log("random message")
    record = tagged_logger.get_latest(user="******")
    assert set(record.tags) == set(["user:foo", "ip:127.0.0.1"])
    assert record.attrs == {"user": "******", "ip": "127.0.0.1"}