I have a function
def func(a,b,c,d):
...
and I am trying to write a decorator that understands the arguments and logs some of them to a different system.
def decorator(func):
def new_func(*args, **kwargs):
if (func.__name__ == 'func'):
a = ?
b = ?
c = ?
d = ?
else:
a = ?
b = ?
c = ?
d = ?
log_to_system(a, b, c, d)
return func(*args, **kwargs)
return new_func
The problem is that the decorator doesn't have an easy way to extract the a,b,c,d values from both the args and the kwargs since the user can pass these in using either positional or keyword arguments. I would also like to keep this generic since this decorator could be used on various different functions.
Is there a library or a utility that can extract the values of the parameters from args and kwargs easily?