/*
 *  Copyright 2011 Eric F. Savage, code@efsavage.com
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package com.ajah.log.http.servlet.filter;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service;

import com.ajah.log.http.RequestEventHandler;
import com.ajah.log.http.request.RequestEvent;
import com.ajah.log.http.request.data.RequestEventManager;
import com.ajah.servlet.AjahFilter;
import com.ajah.util.AjahUtils;

/**
 * Logs HTTP requests.
 * 
 * @author <a href="http://efsavage.com">Eric F. Savage</a>, <a
 *         href="mailto:code@efsavage.com">code@efsavage.com</a>.
 * 
 */
@Service
public class AccessLoggerFilter extends AjahFilter {

	private static final Logger log = Logger.getLogger(AccessLoggerFilter.class.getName());

	@Autowired
	private TaskExecutor taskExecutor;

	@Autowired
	private RequestEventManager requestEventManager;

	/**
	 * Logs requests.
	 */
	@Override
	public void doFilter(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws IOException, ServletException {
		final RequestEvent requestEvent = new RequestEvent(request);
		request.setAttribute("ajahRequestEvent", requestEvent);
		try {
			chain.doFilter(request, response);
		} finally {
			requestEvent.complete();
			log.finest(requestEvent.getUri() + " took " + requestEvent.getDuration() + "ms");
			AjahUtils.requireParam(this.taskExecutor, "taskExecutor");
			this.taskExecutor.execute(new RequestEventHandler(requestEvent, this.requestEventManager));
		}
	}

}

@@ -1311,17 +1311,180 @@
 equests.
+ Will try to determine on it's own if a request should be%0A * logged, but this behavior can be overridden by setting a %7B@link Boolean%7D%0A * request attribute %22logMe%22.
 %0A
-
  * %0A * @
@@ -2287,16 +2287,47 @@
 lete();%0A
+%09%09%09if (isLoggable(request)) %7B%0A%09
 %09%09%09log.f
@@ -2403,16 +2403,17 @@
  %22ms%22);%0A
+%09
 %09%09%09AjahU
@@ -2469,16 +2469,17 @@
 r%22);%0A%09%09%09
+%09
 this.tas
@@ -2564,16 +2564,558 @@
 er));%0A%09%09
-%7D
+%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09/**%0A%09 * Determines if a request should be logged.%0A%09 * %0A%09 * @param request%0A%09 *            The request to examine, required.%0A%09 * @return true if the request should be logged, otherwise false.%0A%09 */%0A%09private static boolean isLoggable(HttpServletRequest request) %7B%0A%09%09if (request.getAttribute(%22logMe%22) != null) %7B%0A%09%09%09return Boolean.TRUE.equals(request.getAttribute(%22logMe%22));%0A%09%09%7D%0A%09%09String uri = request.getRequestURI();%0A%09%09if (uri.equals(%22/favicon.ico%22) %7C%7C uri.endsWith(%22.css%22) %7C%7C uri.endsWith(%22.js%22)) %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09return true;
 %0A%09%7D%0A%0A%7D%0A

Add conditional logging and override