I'm basically trying to track events in an API. There are several routes with different functionalities. I came with something like this:
# defining a decorator like this:
class tracker():
def __init__(self, data):
self.data = data
def __call__(self, function):
@functools.wraps(function)
async def decorated(*args, **kwargs):
self.save_event(*args, **kwargs)
return await function(*args, **kwargs)
return decorated
def save_event(self, *args, **kwargs):
this_would_be_function_arg = self.data
# do something with the data
pass
# to be used like this:
@tracker(data=function_arg):
def my_func(function_arg):
# something...
pass
Is it possible? I know I could access from kwargs, but I won't always know whats being passed, and I don't need every single parameter, so I didn't want to get everything.