+def print_on_call_decorator(func):
+ @functools.wraps(func)
+ def wrapper(self, *args, **kwargs):
+ _debug(type(self).__name__, func.__name__)
+
+ try:
+ return func(self, *args, **kwargs)
+ except Exception, e:
+ _debug("An exception occurred:", traceback.format_exc(e))
+ raise
+
+ return wrapper
+
+class TraceMethodCallMeta(type):
+
+ def __init__(self, name, bases, dict):
+ for func_name, func in dict.iteritems():
+ if inspect.isfunction(func):
+ setattr(self, func_name, print_on_call_decorator(func))
+
+