SHARE
TWEET

Untitled

a guest Nov 8th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Logger(object):
  2.  
  3.     def _logger(self, func):
  4.         if not hasattr(self, 'history'):
  5.             self.history = []
  6.  
  7.         def wrapper(*args, **kwargs):
  8.             self.history.append((func.__name__, args, kwargs))
  9.             return func(*args, **kwargs)
  10.         return wrapper
  11.  
  12.     def __getattribute__(self, name):
  13.         print(name)
  14.  
  15.         item = object.__getattribute__(self, name)
  16.         if callable(item):
  17.             logger = object.__getattribute__(self, '_logger')
  18.             return logger(item)
  19.         return item
  20.  
  21.     def __str__(self):
  22.         return str(self.history)
  23.  
  24.     def goo(self):
  25.         pass
  26.  
  27.  
  28. if __name__ == '__main__':
  29.     pass
  30.  
  31.  
  32. class A(Logger):
  33.     def foo(self):
  34.         pass
  35.  
  36.  
  37. logger = Logger()
  38.  
  39. logger.goo()
  40. logger.goo()
  41. logger.goo()
  42.  
  43. print(logger)
  44.  
  45. print()
  46. print('-------')
  47.  
  48. a = A()
  49.  
  50. a.foo()
  51.  
  52. print(a)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top