def test_logger():
    io = IOLoop.current()
    verbosity_level = 0
    l = Logger()
    l2 = Logger()
    assert id(l) == id(l2)

    @gen.coroutine
    def set_verbosity():
        ch = yield l.set_verbosity(verbosity_level)
        res = yield ch.rx.get()
        raise gen.Return(res)

    empty_resp = io.run_sync(set_verbosity)
    assert empty_resp == [], empty_resp
    verbosity = io.run_sync(io.run_sync(l.verbosity).rx.get)
    assert verbosity == verbosity_level, verbosity
    l.emit(verbosity_level, "nosetest", "test_message", {"attr1": 1, "attr2": 2})
    l.debug("DEBUG_MSG", {"A": 1, "B": 2})
    l.info("INFO_MSG", {"A": 1, "B": 2})
    l.warning("WARNING_MSG", {"A": 1, "B": 2})
    l.error("ERROR_MSG", {"A": 1, "B": 2})
    l.debug("GGGGG")
Exemple #2
0
#!/usr/bin/env python

from cocaine.logger import Logger
from cocaine.worker import Worker
import msgpack

DEFAULT_HEADERS = [('Content-type', 'text/plain')]

log = Logger()

def echo(request, response):
    log.info("entire echo()")
    yield request.read()
    log.info("do echo().request.read()")
    response.write(msgpack.packb((200, DEFAULT_HEADERS)))
    log.info("do echo().response.write() with code and headers")
    response.write("echo")
    log.info("do echo().response.write(echo), next echo().response.close()")
    response.close()
    log.info("do echo().response.close() and exit now")

def main():
    log.info("entire main()")
    w = Worker()
    log.info("do main().Worker()")
    w.run({"http": echo})

if __name__ == "__main__":
    log.info("start echo application worker. prior main()")
    main()