tests/lib/decorator.py
def log_function(desc=None, logger=None,
                 include_args=False, include_kwargs=False,
                 include_return=False):
    '''
    Decorator for a function call.
    Generates log messages when executing the underlying function. Attaches a
    specialized filter to the logger to prepend the description to all log
    messages while executing the function.
    If `desc` is provided, it is used in the log message prefix. If omitted,
    the function name will be used.
    If `logger` is provided, a handler is attached to it during the execution
    of the test function, and restored afterwards. Log statements will then
    include a prefix of `desc` in the messages. If `logger` is omitted, the
    root logger is used.
    If `include_args` is true, then positional arguments are logged prior to
    running the function.
    If `include_kwargs` is true, then keyword-arguments are logged prior to
    running the function.
    If `include_return` is true, then the return value is logged after running
    the function.
    '''

    # pylint: disable=redefined-outer-name
    if desc:
        def get_desc(fn):
            # pylint: disable=unused-argument
            return desc
    else:
        def get_desc(fn):
            if hasattr(fn, '__name__'):
                return getattr(fn, '__name__')
            return '?'

    if logger is None:
        logger = logging.getLogger('sublime-ycmd')

    def log_function_runner(fn):
        ''' Base decorator. Decorates the underlying function. '''

        desc = get_desc(fn)

        @functools.wraps(fn)
        def log_function_run(*args, **kwargs):
            with LoggingContext(logger=logger, desc=desc):
                if include_args and include_kwargs:
                    logger.debug('args, kwargs: %r, %r', args, kwargs)
                elif include_args:
                    logger.debug('args: %r', args)
                elif include_kwargs:
                    logger.debug('kwargs: %r', kwargs)

                result = fn(*args, **kwargs)

                if include_return:
                    logger.debug('return: %r', result)

                return result

        return log_function_run

    return log_function_runner

    Decorator for a function call.
    Generates log messages when executing the underlying function. Attaches a
    specialized filter to the logger to prepend the description to all log
    messages while executing the function.
    If `desc` is provided, it is used in the log message prefix. If omitted,
    the function name will be used.
    If `logger` is provided, a handler is attached to it during the execution
    of the test function, and restored afterwards. Log statements will then
    include a prefix of `desc` in the messages. If `logger` is omitted, the
    root logger is used.
    If `include_args` is true, then positional arguments are logged prior to
    running the function.
    If `include_kwargs` is true, then keyword-arguments are logged prior to
    running the function.
    If `include_return` is true, then the return value is logged after running
    the function.
    
Decorator for a function call.
Generates log messages when executing the underlying function. Attaches a
specialized filter to the logger to prepend the description to all log
messages while executing the function.
If `desc` is provided, it is used in the log message prefix. If omitted,
the function name will be used.
If `logger` is provided, a handler is attached to it during the execution
of the test function, and restored afterwards. Log statements will then
include a prefix of `desc` in the messages. If `logger` is omitted, the
root logger is used.
If `include_args` is true, then positional arguments are logged prior to
running the function.
If `include_kwargs` is true, then keyword-arguments are logged prior to
running the function.
If `include_return` is true, then the return value is logged after running
the function.
Decorator for a function call . Generates log messages when executing the underlying function . Attaches a specialized filter to the logger to prepend the description to all log messages while executing the function . If ` desc ` is provided it is used in the log message prefix . If omitted the function name will be used . If ` logger ` is provided a handler is attached to it during the execution of the test function and restored afterwards . Log statements will then include a prefix of ` desc ` in the messages . If ` logger ` is omitted the root logger is used . If ` include_args ` is true then positional arguments are logged prior to running the function . If ` include_kwargs ` is true then keyword - arguments are logged prior to running the function . If ` include_return ` is true then the return value is logged after running the function .
def log_function(desc=None, logger=None,
                 include_args=False, include_kwargs=False,
                 include_return=False):
    if desc:
        def get_desc(fn):
            return desc
    else:
        def get_desc(fn):
            if hasattr(fn, '__name__'):
                return getattr(fn, '__name__')
            return '?'
    if logger is None:
        logger = logging.getLogger('sublime-ycmd')
    def log_function_runner(fn):
        desc = get_desc(fn)
        @functools.wraps(fn)
        def log_function_run(*args, **kwargs):
            with LoggingContext(logger=logger, desc=desc):
                if include_args and include_kwargs:
                    logger.debug('args, kwargs: %r, %r', args, kwargs)
                elif include_args:
                    logger.debug('args: %r', args)
                elif include_kwargs:
                    logger.debug('kwargs: %r', kwargs)
                result = fn(*args, **kwargs)
                if include_return:
                    logger.debug('return: %r', result)
                return result
        return log_function_run
    return log_function_runner
def log_function ( desc = None , logger = None , include_args = False , include_kwargs = False , include_return = False ) : if desc : def get_desc ( fn ) : return desc else : def get_desc ( fn ) : if hasattr ( fn , '__name__' ) : return getattr ( fn , '__name__' ) return '?' if logger is None : logger = logging . getLogger ( 'sublime-ycmd' ) def log_function_runner ( fn ) : ''' Base decorator. Decorates the underlying function. ''' desc = get_desc ( fn ) @ functools . wraps ( fn ) def log_function_run ( * args , ** kwargs ) : with LoggingContext ( logger = logger , desc = desc ) : if include_args and include_kwargs : logger . debug ( 'args, kwargs: %r, %r' , args , kwargs ) elif include_args : logger . debug ( 'args: %r' , args ) elif include_kwargs : logger . debug ( 'kwargs: %r' , kwargs ) result = fn ( * args , ** kwargs ) if include_return : logger . debug ( 'return: %r' , result ) return result return log_function_run return log_function_runner
Decorator for a function call.
Decorator for a function call .
'''
    Decorator for a function call.
    Generates log messages when executing the underlying function. Attaches a
    specialized filter to the logger to prepend the description to all log
    messages while executing the function.
    If `desc` is provided, it is used in the log message prefix. If omitted,
    the function name will be used.
    If `logger` is provided, a handler is attached to it during the execution
    of the test function, and restored afterwards. Log statements will then
    include a prefix of `desc` in the messages. If `logger` is omitted, the
    root logger is used.
    If `include_args` is true, then positional arguments are logged prior to
    running the function.
    If `include_kwargs` is true, then keyword-arguments are logged prior to
    running the function.
    If `include_return` is true, then the return value is logged after running
    the function.
    ''' # pylint: disable=redefined-outer-name # pylint: disable=unused-argument ''' Base decorator. Decorates the underlying function. '''
desc
logger
include_args
include_kwargs
include_return