Usually this can be accomplished by using a servlet filter. A servlet filter "intercepts" the requests on it's way in and the response on it's way out. You can access all the information you need from the HttpServletRequest and HttpServletResponse and log it however you want.
Simple example:
public class LoggingFilter implements javax.servlet.Filter {
private static final Logger LOGGER = LoggerFactory.getLogger(LoggingFilter.class);
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
// log information from the httpServletRequest like url, params, etc
filterChain.doFilter(servletRequest, servletResponse);
// log information regarding the httpServletResponse like status code, etc
}
}
Registering the filter in your @SpringBootApplication-annotated class:
@Bean
public FilterRegistrationBean loadBalancerHealthCheckHandler() {
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(new LoggingFilter());
registration.addUrlPatterns("/*");
return registration;
}