o
    ei                     @   s(   d Z ddlZddlZddlZdd ZdS )z
Diagnostic utilities
    Nc                    s    fdd}|S )a  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   fdd}|S )zThe decorator returned by the parent function

        :param func: function to be wrapped
        :returns: the function wrapper
        :rtype: callable
        c                     s6   z | i |W S     ddtjt    )a  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
            z6Wrapped func exited with exception. Caller's stack:
%s )	exceptionjoin	tracebackformat_exceptionsysexc_info)argskwargs)funclogger T/var/www/html/pca-backend/venv/lib/python3.10/site-packages/pika/diagnostic_utils.pylog_exception_func_wrap(   s   zVcreate_log_exception_decorator.<locals>.log_exception.<locals>.log_exception_func_wrap)	functoolswraps)r   r   r   )r   r   log_exception    s   z5create_log_exception_decorator.<locals>.log_exceptionr   )r   r   r   r   r   create_log_exception_decorator
   s   r   )__doc__r   r   r   r   r   r   r   r   <module>   s
    