2

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?

PinkeshGjr
  • 8,460
  • 5
  • 41
  • 56
Abhinav
  • 3,322
  • 9
  • 47
  • 63

1 Answers1

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);
peeeto
  • 65
  • 1
  • 4