Capture and log the response body [duplicate]

If I understand you correctly, you want to log the response body?

As @duffymo pointed out, a Filter is indeed a suitable place for this. You can capture the response body by replacing the passed-in ServletResponse with a HttpServletResponseWrapper implementation which basically replaces the HttpServletResponse#getWriter()/getOutputStream() with an own implementation which copies the response body into some buffer. After continuing the filter chain with the replaced response, just capture and log the copy.

You can find in this answer a kickoff example how the doFilter() method can look like.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)