ó
Ì	g]c           @   s7   d  Z  d d l Z d d l Z d d l Z d „  Z d S(   s   
Diagnostic utilities
iÿÿÿÿNc            s   ‡  f d †  } | S(   sÌ  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(   s£   The decorator returned by the parent function

        :param func: function to be wrapped
        :returns: the function wrapper
        :rtype: callable
        c             sJ   y ˆ  |  | Ž  SWn2 ˆ j  d d j t j t j ƒ  Œ  ƒ ƒ ‚  n Xd S(   sð  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
            s6   Wrapped func exited with exception. Caller's stack:
%st    N(   t	   exceptiont   joint	   tracebackt   format_exceptiont   syst   exc_info(   t   argst   kwargs(   t   funct   logger(    s:   /srv/kernel/kteam-tools/dashboard/pika/diagnostic_utils.pyt   log_exception_func_wrap(   s    (   t	   functoolst   wraps(   R	   R   (   R
   (   R	   s:   /srv/kernel/kteam-tools/dashboard/pika/diagnostic_utils.pyt   log_exception    s    !(    (   R
   R   (    (   R
   s:   /srv/kernel/kteam-tools/dashboard/pika/diagnostic_utils.pyt   create_log_exception_decorator
   s    (   t   __doc__R   R   R   R   (    (    (    s:   /srv/kernel/kteam-tools/dashboard/pika/diagnostic_utils.pyt   <module>   s   