Logging request & response in SpringBoot using Groovy

Views: 687   

It will be extremely useful to debug issues if you can log request and response objects in your spring boot applications. This post shows you how can you achieve that using a filter in groovy.

Spring boot comes with CommonsRequestLoggingFilter which has beforeRequest and afterRequest methods which logs the request & responses. But by default, the log statements are in debug mode. So to enable the request and response logging you need to so the following two steps.

1. Enable CommonsRequestLoggingFilter

Add the following code to you Main class where you are starting your Spring Boot application.

 public Filter requestLoggingFilter() {
  CommonsRequestLoggingFilter crlf = new CommonsRequestLoggingFilter();
  return crlf;

2.Enable debug level logging in application.properties file

Add the following line to your application.properties file


That's these configurations will start logging all your request and responses into the log file.

On By