本文介绍了如何在log4j2 xml中配置RestTemplate调试日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将log4j2与xml配置一起使用.我想记录由restTemplate

I am using log4j2 with xml configuration. I want to log all the JSON created by restTemplate

如何在log4j2 xml配置文件中对其进行配置以记录这些内容?

How can I configure it in log4j2 xml configuration file to log these?

推荐答案

如果RestTemplate使用apache http客户端,则log4j2.xml配置可能如下所示:

If your RestTemplate uses apache http client, your log4j2.xml configuration could look like this:

<Logger name="org.springframework.web.client" level="DEBUG" additivity="false">
    <AppenderRef ref="APP" level="DEBUG"/>
</Logger>
<Logger name="org.apache.http.wire" level="DEBUG" additivity="false">
    <AppenderRef ref="APP" level="DEBUG"/>
</Logger>

RestTemplate初始化:

RestTemplate Initialisation:

org.springframework.http.client.HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setReadTimeout(10000);
requestFactory.setConnectTimeout(10000);
RestTemplate restTemplate = new RestTemplate(requestFactory);

这篇关于如何在log4j2 xml中配置RestTemplate调试日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 04:32