Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Log(object):
- def __init__(self):
- self.logs = []
- def __str__(self):
- return self.get_logs(self)
- def __getattribute__(self, item):
- result = super().__getattribute__(item)
- if callable(result):
- result = Log.wrapp(self, result)
- return result
- def get_logs(self, name=True, args=True, kargs=True, res=True):
- result = ""
- for log in self.logs:
- if log[0] != "get_logs":
- if name:
- result = "{0} Name: {1}".format(result, log[0])
- if args:
- result = "{0} Args: {1}".format(result, log[1])
- if kargs:
- result = "{0} Kargs: {1}".format(result, log[2])
- if res:
- result = "{0} Result: {1}".format(result, log[3])
- result += '\n'
- return result
- def wrapp(self, func):
- def wrapper(*args, **kargs):
- #func.__name__, [args, kargs]
- res = func(*args, **kargs)
- log = [func.__name__, args, kargs, res]
- self.logs.append(log)
- return res
- return wrapper
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement