title: Logging all request and response in Spring Boot REST service
body: <p>I use <code>Spring boot</code> and have some <code>REST</code> controllers. I want to logging all request and response. I using external tomacat, not embeded! I write <code>Interceptor</code>:</p>
  
  <pre><code>@Component
  @Log4j2
  public class LoggingWebMvcInterceptor implements HandlerInterceptor {
  
      @Override
      public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
          final ContentCachingRequestWrapper wrapper = new ContentCachingRequestWrapper(request);
          log.debug("REQ!!!! {}", wrapper.getReader().lines().collect(Collectors.joining(System.lineSeparator())));
          return true;
      }
  
      @Override
      public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
          //log.debug("Response: {}", response);
      }
  </code></pre>
  
  <p>And adding his:</p>
  
  <pre><code>@Configuration
  public class WebMvcConfig implements WebMvcConfigurer {
  
      private final LoggingWebMvcInterceptor loggingWebMvcInterceptor;
  
      @Autowired
      public WebMvcConfig(LoggingWebMvcInterceptor loggingWebMvcInterceptor) {
          this.loggingWebMvcInterceptor = loggingWebMvcInterceptor;
      }
  
      @Override
      public void addInterceptors(InterceptorRegistry registry) {
          registry.addInterceptor(loggingWebMvcInterceptor);
      }
  }
  </code></pre>
  
  <p>But It don't work!</p>
  
  <p>When I try <code>POST</code> request, his logging, but I have error: <code>"Required request body is missing</code>.</p>
  
  <p>What am I doing wrong? I created a wrapper for the request! 
  I need to completely log all requests (POST, GET, DELETE, PUT) with headers and body and all responses. How can i do this? Any help, please.</p>