-
Notifications
You must be signed in to change notification settings - Fork 38.5k
RestClient - Consider adding request/response logs #33753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Most of the code in Craig's example is to wrap the response for buffering, and the same can be applied through the @Bean
RestClient.Builder restClientBuilder() {
ClientHttpRequestInterceptor interceptor = (req, reqBody, ex) -> {
ClientHttpResponse response = ex.execute(req, reqBody);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Request body: \n===========\n{}\n===========", new String(reqBody, StandardCharsets.UTF_8));
LOGGER.debug("Response body:\n===========\n{}\n===========", response.getBody());
}
return response;
};
return RestClient.builder()
.requestFactory(new BufferingClientHttpRequestFactory(new JdkClientHttpRequestFactory()))
.requestInterceptor(interceptor);
} However, this forces explicit creation of the underlying We can look to improve buffering by making it more of an internal concern, the way |
The above commit closes #33763, but incorrectly referenced this issue. |
thanks! this.chatClient = builder
.defaultSystem("You are a helpful assistant writing in formal English")
.defaultAdvisors(new SimpleLoggerAdvisor())
.build(); Not sure if we could have something like that with the RestClient? return RestClient.builder()
.requestInterceptor(new SimpleLoggerInterceptor()); |
A built-in interceptor becomes more complex for what should be a simple task. Take I think we should make buffering easy to enable. The actual logging then should be simple. I created #33785, and will close this for now. |
sounds good, thanks! |
Hi,
I commonly add logs to the RestClient based on this nice example from Craig Walls: https://github.com/habuma/logging-interceptor/tree/main
Would it make sense to add request/response logging capabilities as part of the RestClient? That way, it would be simple for everyone to set it up.
Thanks!
The text was updated successfully, but these errors were encountered: