I always think that you should be able to make exceptions for url patterns in web.xml, for example. if you can do something like this:
<filter-mapping> <filter-name>MyFilter</filter-name> <url-pattern> <match>/resources/*</match> <except>/resouces/images/blah.jpg</except> </url-pattern>
but you cannot help you like that!
Obviously, you have access to the URL in the filter through the request object so that you can do something like this:
public void doFilter(ServletRequest sRequest, ServletResponse sResponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest)sRequest; if(!request.getRequestURI.equals("/resources/images/blah.jpg")) { doLogging(); } chain.doFilter(); }
(hardcoded here, but you probably read it from the properties file), although this might not be useful to you, since you mentioned servlets in your request, not URL patterns.
EDIT: another thought. If you don't mind registering after the servlet finishes, you can do something like this:
public void doFilter(ServletRequest sRequest, ServletResponse sResponse, FilterChain chain) throws IOException, ServletException { sRequest.setAttribute("DO_LOGGING", new Boolean(true)); chain.doFilter(); Boolean doLogging = (Boolean)sRequest.getAttribute("DO_LOGGING"); if(doLogging) { doLogging(); } }
and your servlet that you want to exclude from logging can simply set this attribute to false.
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { req.setAttribute("DO_LOGGING", new Boolean(false));