You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
soil/soil/utils.py

23 lines
734 B
Python

7 years ago
import logging
6 years ago
import time
from contextlib import contextmanager
logger = logging.getLogger('soil')
logger.setLevel(logging.INFO)
7 years ago
@contextmanager
7 years ago
def timer(name='task', pre="", function=logger.info, to_object=None):
6 years ago
start = time.time()
function('{}Starting {} at {}.'.format(pre, name,
time.strftime("%X", time.gmtime(start))))
yield start
6 years ago
end = time.time()
function('{}Finished {} at {} in {} seconds'.format(pre, name,
time.strftime("%X", time.gmtime(end)),
str(end-start)))
if to_object:
to_object.start = start
to_object.end = end