/usr/lib/python2.7/dist-packages/kombu/utils/debug.py is in python-kombu 4.1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | """Debugging support."""
from __future__ import absolute_import, unicode_literals
import logging
from vine.utils import wraps
from kombu.five import items, python_2_unicode_compatible
from kombu.log import get_logger
__all__ = ['setup_logging', 'Logwrapped']
def setup_logging(loglevel=logging.DEBUG, loggers=['kombu.connection',
'kombu.channel']):
"""Setup logging to stdout."""
for logger in loggers:
l = get_logger(logger)
l.addHandler(logging.StreamHandler())
l.setLevel(loglevel)
@python_2_unicode_compatible
class Logwrapped(object):
"""Wrap all object methods, to log on call."""
__ignore = ('__enter__', '__exit__')
def __init__(self, instance, logger=None, ident=None):
self.instance = instance
self.logger = get_logger(logger)
self.ident = ident
def __getattr__(self, key):
meth = getattr(self.instance, key)
if not callable(meth) or key in self.__ignore:
return meth
@wraps(meth)
def __wrapped(*args, **kwargs):
info = ''
if self.ident:
info += self.ident.format(self.instance)
info += '{0.__name__}('.format(meth)
if args:
info += ', '.join(map(repr, args))
if kwargs:
if args:
info += ', '
info += ', '.join('{k}={v!r}'.format(k=key, v=value)
for key, value in items(kwargs))
info += ')'
self.logger.debug(info)
return meth(*args, **kwargs)
return __wrapped
def __repr__(self):
return repr(self.instance)
def __dir__(self):
return dir(self.instance)
|