【问题标题】:How can I log all REST calls?如何记录所有 REST 调用?
【发布时间】:2019-02-13 11:06:43
【问题描述】:

我可以看到的调试器内部

JerseyWebTarget { http://host.com/service/method }

我看到它是如何构建参数然后执行 service.method(parms) 调用的。 我可以以某种方式记录通话,以便获得完整的 URL,例如

http://host.com/service/method?id=5

还有更复杂的参数,比如我传输到服务的大型 JSON 文件?

【问题讨论】:

标签: java rest spring-boot logging jersey


【解决方案1】:

内置弹簧为此目的提供了一个过滤器。将下面的 bean 添加到配置文件中。

@Bean
public CommonsRequestLoggingFilter requestLoggingFilter() {
    CommonsRequestLoggingFilter loggingFilter = new CommonsRequestLoggingFilter();
    loggingFilter.setIncludeClientInfo(true);
    loggingFilter.setIncludeQueryString(true);
    loggingFilter.setIncludePayload(true);
    return loggingFilter;
}

另外将org.springframework.web.filter.CommonsRequestLoggingFilter的日志级别更改为DEBUG。

【讨论】:

  • 我将此 Bean 添加到我的配置中。我还将日志级别设置为 DEBUG。我正在运行一个服务方法,然后我有 private static final Logger LOG = LoggerFactory.getLogger(Service.class);它没有帮助。我没有看到电话。
猜你喜欢
  • 2022-08-21
  • 2015-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多