Skip to content

Instantly share code, notes, and snippets.

@flyte
Created November 3, 2015 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flyte/55691ce5812e2d72435d to your computer and use it in GitHub Desktop.
Save flyte/55691ce5812e2d72435d to your computer and use it in GitHub Desktop.
Function decorator to output the function name and arguments to logger.debug
def log_function_call(func):
"""
Function decorator to output the function name and arguments to logger.debug
"""
def inner(*args, **kwargs):
args_str = ", ".join([str(x) for x in args]) if args else ""
kwargs_str = ", ".join(
["%s=%s" % (str(key), str(value)) for key, value in kwargs.items()]) if kwargs else ""
all_args_str = args_str
if all_args_str and kwargs_str:
all_args_str += ", "
all_args_str += kwargs_str
logging.debug("%s(%s)" % (func.func_name, all_args_str))
return func(*args, **kwargs)
return inner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment