l
Ì	g]c               @   s7   d  Z  d d l Z d d l Z d d l Z d „  Z d S(   u   
Diagnostic utilities
i    Nc                s   ‡  f d †  } | S(   uÌ  Create a decorator that logs and reraises any exceptions that escape
    the decorated function

    :param logging.Logger logger:
    :returns: the decorator
    :rtype: callable

    Usage example

    import logging

    from pika.diagnostics_utils import create_log_exception_decorator

    _log_exception = create_log_exception_decorator(logging.getLogger(__name__))

    @_log_exception
    def my_func_or_method():
        raise Exception('Oops!')

    c                s%   t  j ˆ  ƒ ‡  ‡ f d †  ƒ } | S(   u£   The decorator returned by the parent function

        :param func: function to be wrapped
        :returns: the function wrapper
        :rtype: callable
        c                 sK   y ˆ  |  | Ž  SWn3 ˆ j  d d j t j t j ƒ  Œ  ƒ ƒ ‚  Yn Xd S(   uð  The wrapper function returned by the decorator. Invokes the
            function with the given args/kwargs and returns the function's
            return value. If the function exits with an exception, logs the
            exception traceback and re-raises the

            :param args: positional args passed to wrapped function
            :param kwargs: keyword args passed to wrapped function
            :returns: whatever the wrapped function returns
            :rtype: object
            u6   Wrapped func exited with exception. Caller's stack:
%su    N(   u	   exceptionu   joinu	   tracebacku   format_exceptionu   sysu   exc_info(   u   argsu   kwargs(   u   funcu   logger(    u:   /srv/kernel/kteam-tools/dashboard/pika/diagnostic_utils.pyu   log_exception_func_wrap(   s    (   u	   functoolsu   wraps(   u   funcu   log_exception_func_wrap(   u   logger(   u   funcu:   /srv/kernel/kteam-tools/dashboard/pika/diagnostic_utils.pyu   log_exception    s    !(    (   u   loggeru   log_exception(    (   u   loggeru:   /srv/kernel/kteam-tools/dashboard/pika/diagnostic_utils.pyu   create_log_exception_decorator
   s    (   u   __doc__u	   functoolsu   sysu	   tracebacku   create_log_exception_decorator(    (    (    u:   /srv/kernel/kteam-tools/dashboard/pika/diagnostic_utils.pyu   <module>   s   