Answer the question
In order to leave comments, you need to log in
What's wrong with the logging decorator?
Hello!
Please help me to make the correct decorator for logging the start and stop time of the function, my attempt worked on a simple function, but did not work on a complex one:
def time_logging_decorator(func):
def log_time(*args, **kwargs):
start_time = time.time()
log.info('Function "{}" started at {}'.format(
func.__name__,
datetime.datetime.fromtimestamp(start_time).
strftime('%Y-%m-%d %H:%M:%S')
))
func(*args, **kwargs)
log.info("\t\t{} finished in {:.2f} seconds".format(
func.__name__,
time.time() - start_time))
return log_time
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question