Spring RestTemplate Request & Response Logging
It's sometimes useful to log HTTP requests and responses when working with a Spring RestTemplate. If you need fine-grained control over exactly what's logged you can use a custom interceptor to add logging before and after the remote call. Creating an Interceptor You'll need to create a class that extends ClientHttpRequestInterceptor and implement the intercept method as shown below. @Slf4j @Component public class LoggingInterceptor implements ClientHttpRequestInterceptor { @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { logRequest(request, body); ClientHttpResponse response = execution.execute(request, body); logResponse(response); return response; } private void logRequest(HttpRequest request, byte[] body) throws IOException { if (log.isDebugEnabled()) { log.debug("===========================request begin================================================"); log.debug("URI [...]