def log_function(f):
    """ Function decorator that logs every call to that function.
    """
    func_name = f.__name__

    @wraps(f)
    def wrapped(*args, **kwargs):
        name = f.__module__
        logger = logging.getLogger(name)
        level = logging.DEBUG

        if logger.isEnabledFor(level):
            bound_args = getcallargs(f, *args, **kwargs)

            def format(value):
                r = str(value)
                if len(r) > 50:
                    r = r[:50] + "..."
                return r

            func_args = [
                "%s=%s" % (k, format(v)) for k, v in bound_args.items()
            ]

            msg_args = {
                "func_name": func_name,
                "args": ", ".join(func_args)
            }

            _log_debug_as_f(
                f,
                "Invoked '%(func_name)s' with args: %(args)s",
                msg_args
            )

        return f(*args, **kwargs)

    wrapped.__name__ = func_name
    return wrapped
dataset/ETHPy150Open matrix-org/synapse/synapse/util/logutils.py/log_function/original