I'm currently integrating request / response logging into a REST service using Spring Boot. For requests, I chose the CommonsRequestLoggingFilter as provided by Spring:
@Bean
public CommonsRequestLoggingFilter requestLoggingFilter() {
CommonsRequestLoggingFilter loggingFilter = new CommonsRequestLoggingFilter();
loggingFilter.setIncludeClientInfo(false);
loggingFilter.setIncludeQueryString(true);
loggingFilter.setIncludePayload(true);
loggingFilter.setMaxPayloadLength(1024);
return loggingFilter;
}
And in the configuration file:
logging.level.org.springframework.web.filter.CommonsRequestLoggingFilter=DEBUG
For reponses, however, there seems to be no corresponding class? Is there a similar way to log the server response in Spring?
EDIT: Specically, what I see with the above setup is nothing in BeforeRequest:
2017-06-28 09:32:32.258 DEBUG 22872 --- [http-nio-8081-exec-2] o.s.w.f.CommonsRequestLoggingFilter : Before request [uri=/someApp/someObject]
The request payload as AfterRequest:
2017-06-28 09:32:32.272 DEBUG 22872 --- [http-nio-8081-exec-2] o.s.w.f.CommonsRequestLoggingFilter :
After request [uri=/someApp/someResource;payload={
"someObject": {
"lastName": "Doe",
"reference": "123456789"
}
}
]
And the actual response is nowhere in the log.
Nevermind,
I ended up implementing my own filter that can log responses as well. Based on GenericFilterBean, wrapping HttpResponse and HttpRequest so the streams don't get closed.
It's still strange to me that Spring provides a class for logging requests, but not for responses...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With