I am using CommonsRequestLoggingFilter to log incoming requests, but I am interested only in the start of the request and don`t want to log after request. I have extended logging filter to ignore logging after request like this:

public class CommonsRequestLoggingFilterIgnoringAfterRequest extends CommonsRequestLoggingFilter {

    @Override
    protected void afterRequest(HttpServletRequest request, String message) {
        // do not log after request
    }
}

But it would be nice to introduce property like boolean ignoreAfterRequest which I could pass to out of the box request logging filter. Would it make sense to introduce it?

Comment From: Drezir

I think that it's wrong to log in after handling. I have implemented custom solution for our company and we are logging in before method. I think that current implementation supports only those request that are sucessful and do not throw any exception.

Comment From: rstoyanchev

The filter already has a number of properties and at some point it is better to extend and do what you need. So this is meant to be extended and overriding beforeRequest and afterRequest as you have done is intentional. Keep in mind that the request body is consumed lazily rather than eagerly and may not yet be visible in beforeRequest.

Comment From: OskarsPakers

I see. It indeed has quite a lot of properties. How about making a separate, simpler filter like CommonsRequestUrlLoggingFilter that would log nothing but request URL and before request?

Comment From: rstoyanchev

It's the same issue again, lots of possibilities and no one way to do it. Note that you can also get such basic request logging (minus the body) through the DispatcherServlet as explained in this section of the docs.

Comment From: OskarsPakers

Indeed. org.springframework.web.servlet.DispatcherServlet: DEBUG logs only request url, but it also returns outcome

o.s.web.servlet.DispatcherServlet        : GET "/v3/api-docs/swagger-config", parameters={}
o.s.web.servlet.DispatcherServlet        : Completed 200 OK

So if that is the outcome that you don`t see a point to extend CommonsRequestLoggingFilter with parameters shouldLogBeforeRequest and shouldLogAfterRequest then I think this issue should be closed.

Comment From: rstoyanchev

I don't quite understand the reason why the above does not meet your needs?

Comment From: OskarsPakers

Because I would like to log only the beginning of the request.

Comment From: rstoyanchev

Sure but it's not clear why that is. If you want to do it for your application, that's fine but when you want it added in the framework and made widely available it is important to explain the Javadoc why something is available and when it is relevant.

Comment From: OskarsPakers

Well, our use case is that our service is being used by external parties and it is important to identify how they use the API and which endpoint they call. While I find verbose and irrelevant to log response codes because we log exceptions if they occur and if there is no exception response status code is always 200 OK. Therefore, it would be nice to log nothing but when the request URL when it is received.

Comment From: rstoyanchev

Okay, thanks for clarifying. I will close this for now since this is all doable. We can always reopen if there is more demand.