Home > database >  How to Disable logging in Spring RestTemplate
How to Disable logging in Spring RestTemplate

Time:02-02

I am trying to reduce the logging of RestTemplate.

ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);

When the statement is executed it prints a Response. I am doing a lot of api calls using this and this is creating a lot of logging noise in my console.

Is there any way I can reduce or disable the logging for this? I only want to avoid logging in this part of the code not the whole application.

CodePudding user response:

You can disable the logging for the RestTemplate by setting the log level to OFF.

To do this, add the following line of code to your application:

Logger logger = LoggerFactory.getLogger(RestTemplate.class);
logger.setLevel(Level.OFF);

CodePudding user response:

I would turn off logging in your application.properties file:

logging.level.org.springframework.web.client.RestTemplate=ERROR
  • Related