#!/usr/bin/env python3 from datetime import datetime import functools def invocation_logged(func): @functools.wraps(func) def wrapper(*args, **kwargs): now = datetime.now() timestamp = now.strftime("%d-%b-%Y (%H:%M:%S.%f)") print("%s(%s): Entered function" % (func.__name__, timestamp)) ret = func(*args, **kwargs) now = datetime.now() timestamp = now.strftime("%d-%b-%Y (%H:%M:%S.%f)") print("%s(%s): Exited function" % (func.__name__, timestamp)) return ret return wrapper # Test # @invocation_logged # def f(x): # print(x * x) # return x * x # # q = f(10) # print(q)