How to configure RestTemplate debug logging in log4j2 xml

霸气de小男生 提交于 2019-12-23 22:22:45

问题


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

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


回答1:


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 Initialisation:

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


来源:https://stackoverflow.com/questions/28215119/how-to-configure-resttemplate-debug-logging-in-log4j2-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!