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
  • 7,978
  • 5
  • 37
  • 54
Abhinav
  • 3,142
  • 6
  • 44
  • 60

1 Answers1

0

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
  • 55
  • 1
  • 4