From: Scott Gasch Date: Sat, 28 Nov 2020 21:25:53 +0000 (-0800) Subject: Adds decorators X-Git-Url: https://wannabe.guru.org/gitweb/?a=commitdiff_plain;h=41262fc75551d35bcc9979011078b0e5b4e7b36a;p=kiosk.git Adds decorators --- diff --git a/decorators.py b/decorators.py new file mode 100644 index 0000000..7a08879 --- /dev/null +++ b/decorators.py @@ -0,0 +1,24 @@ +from datetime import datetime +import functools + +def invokation_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 +#@invokation_logged +#def f(x): +# print(x * x) +# return x * x +# +#q = f(10) +#print(q)