<commit_before>import logging
import sys
import types

from functools import wraps
from functools import partial


__all__ = ['breakOnEnter', 'breakOnException', 'breakOnExit', 'breakOnResult',
           'callOnEnter', 'callOnException', 'callOnExit', 'callOnResult',
           'logCalls', 'logOnException', 'skip', 'substitute', 'tap']


def logCalls(func=None, *, enterFmtStr=None, exitFmtStr=None,
             level=logging.DEBUG, logName=None, timerFunc=None):
    '''
    A decorator that logs call information about a function. Logging is
    performed when the decorated function is entered as well as exited.  The
    total number of times that the function has been called and the time that
    each call takes is logged in addition to the name of the function.

    enterFmtStr : A formatted string to output when the decorated function is
        entered. The format() function is called on the string with locals().
        If not specified, this argument is set to
        '[{callNumber}] Calling {funcName}()'.

    exitFmtStr : A formatted string to output when the decorated function is
        exited. The format() function is called on the string with locals(). If
        not specified, this argument is set to
        '[{callNumber}] Exiting {funcName}()\t[{callTime} seconds]'.

    level : The logging level to use for logging calls. This must be one of the
        logging level constants defined in the logging module.

    logName : The name of the log which is written to by logging calls. If not
        given, the name of the module in which the decorated function is
        defined is used, i.e. func.__module__.

    timerFunc : The function to use for timing the duration of function calls.
        This function is called before and after the decorated function is
        called. The difference between the two return values of the timing
        function is used as the duration of the function call. If not given,
        time.process_time is used.
    '''

    if func is None:
        return partial(logCalls, enterFmtStr=enterFmtStr,
                       exitFmtStr=exitFmtStr, level=level, logName=logName,
                       timerFunc=timerFunc)

    # The number of times the wrapped function has been called
    nCalls = 0

    if enterFmtStr is None:
        enterFmtStr = '[{callNumber}] Calling {funcName}()'

    if exitFmtStr is None:
        exitFmtStr = ('[{callNumber}] Exiting {funcName}()\t[{callTime} '
                      'seconds]')

    if logName is None:
        logName = func.__module__

    if timerFunc is None:
        import time
        timerFunc = time.process_time

    @wraps(func)
    def wrapper(*args, **kwargs):
        nonlocal nCalls
        funcName = func.__name__

        callNumber = nCalls
        logger = logging.getLogger(logName)
        logMsg = enterFmtStr.format(**locals())
        logger.log(level, logMsg)
        nCalls = nCalls + 1

        start = timerFunc()
        result = func(*args, **kwargs)
        end = timerFunc()

        callTime = round(end - start, 4)  # TODO: use string formatting instead
        logMsg = exitFmtStr.format(**locals())
        logger.log(level, logMsg)

        return result
    return wrapper


def logOnException(func=None, *, exceptionList=Exception, suppress=False,<commit_msg>Change default timing function.<commit_after>import logging
import sys
import types

from functools import wraps
from functools import partial


__all__ = ['breakOnEnter', 'breakOnException', 'breakOnExit', 'breakOnResult',
           'callOnEnter', 'callOnException', 'callOnExit', 'callOnResult',
           'logCalls', 'logOnException', 'skip', 'substitute', 'tap']


def logCalls(func=None, *, enterFmtStr=None, exitFmtStr=None,
             level=logging.DEBUG, logName=None, timerFunc=None):
    '''
    A decorator that logs call information about a function. Logging is
    performed when the decorated function is entered as well as exited.  The
    total number of times that the function has been called and the time that
    each call takes is logged in addition to the name of the function.

    enterFmtStr : A formatted string to output when the decorated function is
        entered. The format() function is called on the string with locals().
        If not specified, this argument is set to
        '[{callNumber}] Calling {funcName}()'.

    exitFmtStr : A formatted string to output when the decorated function is
        exited. The format() function is called on the string with locals(). If
        not specified, this argument is set to
        '[{callNumber}] Exiting {funcName}()\t[{callTime} seconds]'.

    level : The logging level to use for logging calls. This must be one of the
        logging level constants defined in the logging module.

    logName : The name of the log which is written to by logging calls. If not
        given, the name of the module in which the decorated function is
        defined is used, i.e. func.__module__.

    timerFunc : The function to use for timing the duration of function calls.
        This function is called before and after the decorated function is
        called. The difference between the two return values of the timing
        function is used as the duration of the function call. If not given,
        time.time is used.
    '''

    if func is None:
        return partial(logCalls, enterFmtStr=enterFmtStr,
                       exitFmtStr=exitFmtStr, level=level, logName=logName,
                       timerFunc=timerFunc)

    # The number of times the wrapped function has been called
    nCalls = 0

    if enterFmtStr is None:
        enterFmtStr = '[{callNumber}] Calling {funcName}()'

    if exitFmtStr is None:
        exitFmtStr = ('[{callNumber}] Exiting {funcName}()\t[{callTime} '
                      'seconds]')

    if logName is None:
        logName = func.__module__

    if timerFunc is None:
        import time
        timerFunc = time.time

    @wraps(func)
    def wrapper(*args, **kwargs):
        nonlocal nCalls
        funcName = func.__name__

        callNumber = nCalls
        logger = logging.getLogger(logName)
        logMsg = enterFmtStr.format(**locals())
        logger.log(level, logMsg)
        nCalls = nCalls + 1

        start = timerFunc()
        result = func(*args, **kwargs)
        end = timerFunc()

        callTime = round(end - start, 4)  # TODO: use string formatting instead
        logMsg = exitFmtStr.format(**locals())
        logger.log(level, logMsg)

        return result
    return wrapper


def logOnException(func=None, *, exceptionList=Exception, suppress=False,
{'fraction_non_alphanumeric': 0.07751354605659241, 'fraction_numerical': 0.0009030704394942806, 'mean_word_length': 2.697829716193656, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3169407', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1749, 'n_words': 718}