utils: Add time_logger context manager
This commit is contained in:
parent
4e30fb2f48
commit
e06c7708a7
16
mopidy/utils/timer.py
Normal file
16
mopidy/utils/timer.py
Normal file
@ -0,0 +1,16 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import logging
|
||||
import time
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
TRACE = logging.getLevelName('TRACE')
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def time_logger(name, level=TRACE):
|
||||
start = time.time()
|
||||
yield
|
||||
logger.log(level, '%s took %dms', name, (time.time() - start) * 1000)
|
||||
Loading…
Reference in New Issue
Block a user