def do_listen():
    logger.configure(prefix=options.prefix)
    logger.subscribe()
    for record in logger.listen():
        ts = record.ts.strftime(options.time_format)
        formatted = '{0} {1}'.format(ts, str(record))
        print(formatted)
示例#2
0
def test_pubsub():
    generator = multiprocessing.Process(target=do_generate_two_records)
    generator.start()
    messages = []
    tagged_logger.subscribe()
    for message in tagged_logger.listen():
        messages.append(message)
        if len(messages) == 2:
            break
    tagged_logger.unsubscribe()
    generator.join()
    msg1, msg2 = messages
    assert isinstance(msg1, tagged_logger.Log)
    assert isinstance(msg2, tagged_logger.Log)
    assert msg1.message == 'foo'
    assert msg2.message == 'bar'