https://github.com/onready/spring-resttemplate-logger
A simple way to log RestTemplate requests and responses
https://github.com/onready/spring-resttemplate-logger
Last synced: 5 months ago
JSON representation
A simple way to log RestTemplate requests and responses
- Host: GitHub
- URL: https://github.com/onready/spring-resttemplate-logger
- Owner: onready
- License: mit
- Created: 2018-07-31T04:51:26.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-09T23:52:04.000Z (over 3 years ago)
- Last Synced: 2025-07-10T21:47:14.349Z (12 months ago)
- Language: Java
- Size: 21.5 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: License.txt
Awesome Lists containing this project
README
# Spring Rest Template Logger
A simple way to log Spring RestTemplate requests and responses.
## Requirements
- Spring web 4+
- Slf4j 1.7.7+
## How it works
This project includes a new RestTemplate interceptor (RequestLoggerInterceptor) that logs the request and response. For this, you have to add this interceptor to your RestTemplate instance. Also, you will need to change the default request factory for a BufferingClientHttpRequestFactory, this is necessary to log de response body.
## How to use
#### Without Spring Boot
Add the dependency to `pom.xml`
```xml
ar.com.onready
spring-resttemplate-logger
1.0.0
```
Then, configure your RestTemplate instance:
```java
RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()));
List interceptors = restTemplate.getInterceptors();
if (CollectionUtils.isEmpty(interceptors)) {
interceptors = new ArrayList(1);
}
interceptors.add(new RequestLoggerInterceptor());
restTemplate.setInterceptors(interceptors);
```
## Important
In order to view the logs, the package `ar.com.onready.springrequestlogger` must be log in debug mode.