def log(logger=None, start_message='<STR_LIT>', end_message='<STR_LIT>'):
def actual_log(f, real_logger=logger):<EOL><INDENT>logger = real_logger or _logger<EOL>@wraps(f)<EOL>def timed(*args, **kwargs):<EOL><INDENT>logger.info(f'<STR_LIT>')<EOL>start = time.time()<EOL>res = f(*args, **kwargs)<EOL>end = time.time()<EOL>logger.info(f'<STR_LIT>')<EOL>return res<EOL><DEDENT>return timed<EOL><DEDENT>if callable(logger):<EOL><INDENT>return actual_log(logger, real_logger=None)<EOL><DEDENT>return actual_log<EOL>
Basic log decorator
Can be used as :
- @log (with default logger)
- @log(mylogger)
- @log(start_message='Hello !", logger=mylogger, end_message='Bye !')