Created
November 3, 2015 12:32
-
-
Save flyte/55691ce5812e2d72435d to your computer and use it in GitHub Desktop.
Function decorator to output the function name and arguments to logger.debug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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