예제 #1
0
def test_expire_archive_func():
    archive = []

    def do_archive(record):
        archive.append(record)

    tagged_logger.log("foo", ts=datetime.datetime(2012, 1, 1), expire=1)
    tagged_logger.expire(archive_func=do_archive)
    assert len(archive) == 1
예제 #2
0
def test_expire_archive_func_in_configure():
    archive = []

    def do_archive(record):
        archive.append(record)

    tagged_logger.configure(prefix=prefix, archive_func=do_archive, **redis_kwargs)
    tagged_logger.log("foo", ts=datetime.datetime(2012, 1, 1), expire=1)
    tagged_logger.expire()
    assert len(archive) == 1
예제 #3
0
def test_expire():
    tagged_logger.log("1st January", expire=datetime.datetime(2012, 1, 1))
    tagged_logger.log("2nd January", expire=datetime.datetime(2012, 1, 2))

    expired = tagged_logger.expire(ts=datetime.datetime(2011, 12, 30, 23, 59))
    assert expired == 0
    assert len(tagged_logger.get()) == 2  # nothing has expired

    expired = tagged_logger.expire(ts=datetime.datetime(2012, 1, 1, 23, 59))
    assert expired == 1
    assert len(tagged_logger.get()) == 1  # one message has expired

    expired = tagged_logger.expire(ts=datetime.datetime(2012, 1, 2, 23, 59))
    assert expired == 1
    assert len(tagged_logger.get()) == 0  # all messages have expired