Anurag Sharma
Anurag Sharma

Reputation: 2605

Spring MVC: log all requests, even the resource not founds

How can I log all requests in Spring MVC, even the resource not founds ones?

I guess interceptors can not log resource not found requests. What do you suggest?

Upvotes: 1

Views: 239

Answers (1)

Piotr Podraza
Piotr Podraza

Reputation: 2039

Have you tried using implementation of javax.servlet.Filter?

Filter in contrary to Spring's interceptor is part of a Java's standard and is executed by the servlet container for each incoming HTTP request..

Spring MVC use exactly one servlet and that is DispatcherServlet which, as the name suggest, disptach received request to correct controller which process the request futher.

Spring even provide few concrete implementations of Filter that can log incoming request for you such as: CommonsRequestLoggingFilter or ServletContextRequestLoggingFilter.

You can choose one of the above implementations or implement Filter interface by yourself - whatever you decide, by using Filter you should be able to log every single request received by your servlet container.

Upvotes: 2

Related Questions