Java 打印特定函数中的所有子方法调用和参数

Java 打印特定函数中的所有子方法调用和参数,java,byte-buddy,Java,Byte Buddy,我试图通过这个例子,但无法找到一个具体的例子来帮助我理解如何跟踪特定方法中的所有方法调用及其参数(基于elementMatcher) 我想跟踪的方法是getCustomer,它打算使用ByteBuddy获取getCustomer中调用的所有方法的元数据,并访问传递给每个方法的所有参数 我想把方法打印出来 i) customerRepository.findOne,以customerId值作为参数 ii)以客户价值为参数的log.info 等等。。。有返回值 public Customer get

我试图通过这个例子,但无法找到一个具体的例子来帮助我理解如何跟踪特定方法中的所有方法调用及其参数(基于elementMatcher)

我想跟踪的方法是getCustomer,它打算使用ByteBuddy获取getCustomer中调用的所有方法的元数据,并访问传递给每个方法的所有参数

我想把方法打印出来

i) customerRepository.findOne,以customerId值作为参数

ii)以客户价值为参数的log.info

等等。。。有返回值

public Customer getCustomer(@PathVariable("customerId") Long customerId) {

        /* validate customer Id parameter */
        if (null == customerId) {
            throw new InvalidCustomerRequestException();
        }

        Customer customer = customerRepository.findOne(customerId);

        if (null == customer) {
            throw new CustomerNotFoundException();
        }

        log.info("Customer Data is {}", customer);

        try {
            dispatchEventToSalesForce(String.format(" Customer %s Logged into SalesForce", customer));
        } catch (Exception e) {
            log.error("Failed to Dispatch Event to SalesForce . Details {} ", e.getLocalizedMessage());

        }

        return customer;
    }

有人能帮我翻译一下拦截器代码片段吗,这样我现在就可以按照指南进行操作了,用Byte Buddy做这件事并不容易。您正在查找的组件称为
MemberSubstitution
,它允许您替换方法中的方法调用和字段访问。您想做的是添加一个方法调用,该调用捕获当前正在开发的参数,作为上述API的一个附加功能

或者,如果您知道所有被调用的方法,您可以拦截它们,并浏览堆栈跟踪以验证它们是否是从所讨论的方法调用的