human
Complete this python program:
def log_method(function):
assistant
#Here is the Python code you requested.

    """Decorator that log calls to the given function.
    """
    label = ('acceptance:' + function.__name__)
    def log_result(result, action):
        action.add_success_fields(result=_ensure_encodeable(result))
        return result
    @wraps(function)
    def wrapper(self, *args, **kwargs):
        serializable_args = tuple((_ensure_encodeable(a) for a in args))
        serializable_kwargs = {}
        for kwarg in kwargs:
            serializable_kwargs[kwarg] = _ensure_encodeable(kwargs[kwarg])
        context = start_action(action_type=label, args=serializable_args, kwargs=serializable_kwargs)
        with context.context():
            d = DeferredContext(function(self, *args, **kwargs))
            d.addCallback(log_result, context)
            d.addActionFinish()
            return d.result
    return wrapper