onefinestay/nameko — pull request #140 by mattbennett (2014-08-15 17:18:17+00:00)
Title: prettify logging

Alternatively, modify the logger in place so you can do ``log.time`` (this might be a horrible idea)

``` python
def add_timing_logger(logger, precision=3, level=logging.DEBUG):
""" ...

Usage::

>>> logger = logging.getLogger('foobar')
>>> add_timing_logger(logger, level=logging.INFO, precision=2)
>>>
>>> with log.time("hello %s", "world"):
... time.sleep(1)
INFO:foobar:hello world in 1.00s
"""
log_method = partial(logger.log, level)
log.time = partial(_log_time, log_method, precision)
```