Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. class Log(object):
  2.     def __init__(self):
  3.         self.logs = []
  4.  
  5.     def __str__(self):
  6.         return self.get_logs(self)
  7.  
  8.     def __getattribute__(self, item):
  9.         result = super().__getattribute__(item)
  10.         if callable(result):
  11.             result = Log.wrapp(self, result)
  12.         return result
  13.  
  14.     def get_logs(self, name=True, args=True, kargs=True, res=True):
  15.         result = ""
  16.         for log in self.logs:
  17.             if log[0] != "get_logs":
  18.                 if name:
  19.                     result = "{0} Name: {1}".format(result, log[0])
  20.                 if args:
  21.                     result = "{0} Args: {1}".format(result, log[1])
  22.                 if kargs:
  23.                     result = "{0} Kargs: {1}".format(result, log[2])
  24.                 if res:
  25.                     result = "{0} Result: {1}".format(result, log[3])
  26.                 result += '\n'
  27.         return result
  28.  
  29.     def wrapp(self, func):
  30.         def wrapper(*args, **kargs):
  31.             #func.__name__, [args, kargs]
  32.             res = func(*args, **kargs)
  33.             log = [func.__name__, args, kargs, res]
  34.             self.logs.append(log)
  35.             return res
  36.         return wrapper
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement