Java Spring Boot Log Response with Payloads
I am currently integrating request / response logging into a REST service using Spring Boot. For requests, I chose 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 config file:
logging.level.org.springframework.web.filter.CommonsRequestLoggingFilter=DEBUG
However, there is no corresponding class for the answers? Is there a similar way to log a server response in Spring?
EDIT: In particular, what I see with the above setup doesn't matter 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]
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 answer is nowhere in the log.
+4
source to share
3 answers