7a088796a9cce63616412a8cbfccf16c2f8bb2fa
[kiosk.git] / decorators.py
1 from datetime import datetime
2 import functools
3
4 def invokation_logged(func):
5     @functools.wraps(func)
6     def wrapper(*args, **kwargs):
7         now = datetime.now()
8         timestamp = now.strftime("%d-%b-%Y (%H:%M:%S.%f)")
9         print("%s(%s): Entered function" % (func.__name__, timestamp))
10         ret = func(*args, **kwargs)
11         now = datetime.now()
12         timestamp = now.strftime("%d-%b-%Y (%H:%M:%S.%f)")
13         print("%s(%s): Exited function" % (func.__name__, timestamp))
14         return ret
15     return wrapper
16
17 # Test
18 #@invokation_logged
19 #def f(x):
20 #    print(x * x)
21 #    return x * x
22 #
23 #q = f(10)
24 #print(q)