Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

debug.py 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. """
  2. kombu.utils.debug
  3. =================
  4. Debugging support.
  5. """
  6. from __future__ import absolute_import
  7. import logging
  8. from functools import wraps
  9. from kombu.five import items
  10. from kombu.log import get_logger
  11. __all__ = ['setup_logging', 'Logwrapped']
  12. def setup_logging(loglevel=logging.DEBUG, loggers=['kombu.connection',
  13. 'kombu.channel']):
  14. for logger in loggers:
  15. l = get_logger(logger)
  16. l.addHandler(logging.StreamHandler())
  17. l.setLevel(loglevel)
  18. class Logwrapped(object):
  19. __ignore = ('__enter__', '__exit__')
  20. def __init__(self, instance, logger=None, ident=None):
  21. self.instance = instance
  22. self.logger = get_logger(logger)
  23. self.ident = ident
  24. def __getattr__(self, key):
  25. meth = getattr(self.instance, key)
  26. if not callable(meth) or key in self.__ignore:
  27. return meth
  28. @wraps(meth)
  29. def __wrapped(*args, **kwargs):
  30. info = ''
  31. if self.ident:
  32. info += self.ident.format(self.instance)
  33. info += '{0.__name__}('.format(meth)
  34. if args:
  35. info += ', '.join(map(repr, args))
  36. if kwargs:
  37. if args:
  38. info += ', '
  39. info += ', '.join('{k}={v!r}'.format(k=key, v=value)
  40. for key, value in items(kwargs))
  41. info += ')'
  42. self.logger.debug(info)
  43. return meth(*args, **kwargs)
  44. return __wrapped
  45. def __repr__(self):
  46. return repr(self.instance)
  47. def __dir__(self):
  48. return dir(self.instance)