How to configure RestTemplate debug logging in log4j2 xml

I am using log4j2 with xml configuration. I want to write all JSON created usingrestTemplate

How to configure it in the log4j2 xml configuration file to register them?

+2
source share
1 answer

If your RestTemplate uses the apache http client, your log4j2.xml configuration might 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>

Initializing RestTemplate:

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

All Articles