Example #1
0
def log_exception(name, **kwargs):
    """Logs an exception, along with relevant information such as message,
    traceback, and anything provided pertinent to the situation. This function
    does nothing unless called while an exception is being handled.

    :param name: ``name`` as passed in to :py:func:`logging.getLogger()`.
    :param kwargs: Other keywords may be passed in and will be included in the
                   produced log line.

    """
    type, value, tb = sys.exc_info()
    if not value:
        return
    exc_repr = reprlib.Repr()
    exc_repr.maxstring = 1000
    logger = logging.getLogger(name)
    data = kwargs.copy()
    data['message'] = str(value)
    data['traceback'] = traceback.format_exception(type, value, tb)
    data['args'] = value.args
    data_str = ' '.join([
        '='.join((key, exc_repr.repr(val)))
        for key, val in sorted(data.items())
    ])
    logger.error('exception:{0}:unhandled {1}'.format(type.__name__, data_str))
Example #2
0
import six
from six.moves import reprlib

PY3, PY2 = six.PY3, not six.PY3

from .pyobj import Frame, Block, Method, Function, Generator

log = logging.getLogger(__name__)

if six.PY3:
    byteint = lambda b: b
else:
    byteint = ord

# Create a repr that won't overflow.
repr_obj = reprlib.Repr()
repr_obj.maxother = 120
repper = repr_obj.repr


class VirtualMachineError(Exception):
    """For raising errors in the operation of the VM."""
    pass


class VirtualMachine(object):
    def __init__(self):
        # The call stack of frames.
        self.frames = []
        # The current frame.
        self.frame = None
Example #3
0
        When was the deferred for this request canceled? `None` if it hasn't
        been. The queue entry for a cancelled request is kept around if it has
        been sent so that the response correlation logic can differentiate
        between responses that were too late vs. responses to requests that
        were never sent.
    """
    correlationId = attr.ib()
    request = attr.ib(repr=False)
    expectResponse = attr.ib()
    d = attr.ib()
    queued = attr.ib()
    sent = attr.ib(default=None)
    cancelled = attr.ib(default=None)


_aLongerRepr = reprlib.Repr()
_aLongerRepr.maxstring = 1024  # Python 2: str is bytes
_aLongerRepr.maxother = 1024  # Python 3: bytes is not str


class _KafkaBrokerClient(ClientFactory):
    """
    The low-level client which handles transport to a single Kafka broker.

    The KafkaBrokerClient object is responsible for maintaining a connection to
    a single Kafka broker, reconnecting as needed, over which it sends requests
    and receives responses. Callers make requests with :py:method:`makeRequest`
    """
    protocol = KafkaProtocol

    # Reduce log spam from twisted
Example #4
0
        return
    exc_repr = reprlib.Repr()
    exc_repr.maxstring = 1000
    logger = logging.getLogger(name)
    data = kwargs.copy()
    data['message'] = str(value)
    data['traceback'] = traceback.format_exception(type, value, tb)
    data['args'] = value.args
    data_str = ' '.join([
        '='.join((key, exc_repr.repr(val)))
        for key, val in sorted(data.items())
    ])
    logger.error('exception:{0}:unhandled {1}'.format(type.__name__, data_str))


log_repr = reprlib.Repr()
log_repr.maxstring = 100


def logline(log, type, typeid, operation, **data):
    if not data:
        log('{0}:{1}:{2}'.format(type, typeid, operation))
    else:
        data_str = ' '.join([
            '='.join((key, log_repr.repr(val)))
            for key, val in sorted(data.items())
        ])
        log('{0}:{1}:{2} {3}'.format(type, typeid, operation, data_str))


parseline_pattern = re.compile(r'^([^:]+):([^:]+):(\S+) ?(.*)$')