0

Is it possible to have the AppEngine dev server output a quick log message to the eclipse console every time it serves a static file?

For example, if my website loads "background.gif" (as a static file from the file system), I would like to see a line like "GET request for static file /war/resources/images/background.gif by 127.0.0.1" show up in the Eclipse console.

Maybe there is a command-line switch for tomcat (the server that appengine uses locally)? I couldn't find anything relevant here... But I did find some documentation about an "access log valve (?!?)" which might look promising, but I don't know if this does what I am looking for, or even if it does, how I can get any potential output to show up in the Eclipse console.

Markus A.
  • 12,349
  • 8
  • 52
  • 116

1 Answers1

0

You can use a servlet Filter to intercept all requests:

public class LoggingFilter implements Filter {

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

  @Override
  public void init(FilterConfig filterConfig) throws ServletException {
  } 

  @Override
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

    HttpServletRequest httpRequest = ((HttpServletRequest) request);
    log.info(httpRequest.getMethod() + " request for " + httpRequest.getRequestURI() + " from " + httpRequest.getRemoteAddr());
    request.getRequestDispatcher(httpRequest.getRequestURI()).forward(request, response);
  }

  @Override
  public void destroy() {
  }
}

The only problem is that you can not distinguish between requests static and dynamic content. In order to do so, you could put all static content under one directory and that map this Filter to only that path.

Peter Knego
  • 79,991
  • 11
  • 123
  • 154