title: Capturing request body content in Grails 4 for logging
body: <p>Building out a new API using Grails 4, and I would like to have the option of logging the full request (headers, method, content, etc). I can see the request in an Interceptor, but the content can only be read once (using <code>HttpServletRequest.getInputStream()</code>), so reading it in the Interceptor prevents the content from being available in the Controller.</p>
  
  <p>There are some similar questions about this on Stack Overflow already that address this need by using Grails Filters.</p>
  
  <p>One reason I don't want to go down that path is that, according to the Grails docs, <a href="https://docs.grails.org/3.0.0/guide/single.html#interceptors" rel="nofollow noreferrer">Filters are now considered deprecated (as of v3.0), and Interceptors should instead be used</a>. Unfortunately, none of the solutions I can find work with Interceptors. I tried a couple of those solutions myself that involve wrapping the request inside of a <code>HttpServletRequestWrapper</code> to cache the body content and ran into the same issues as others with trying to get it to work with an Interceptor.</p>
  
  <p>I have seen suggestions to use Java Servlet Filters, it's not obvious how that's different from Grails Filters, or if they should also be avoided.</p>
  
  <p>Edit: As noted in comments below, I didn't mention that I'm using command objects, and the solution needs to work with those. I'm also using a number of other Grails features that I'm not sure will be affected by whatever solutions will be proposed, so if there are limitations to the proposed solution, it would be good to know about those.</p>