Closed GoogleCodeExporter closed 9 years ago
You can add a servlet filter to log whatever you want, with whatever logging
framework you want.
For example, with the following class:
package mypackage;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
public class LogFilter implements Filter {
private Logger logger;
public void init(FilterConfig filterConfig) throws ServletException {
logger = Logger.getLogger(getClass());
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
// it doesn't seem necessary to log dozens of requests on resources or graphics
if (httpRequest.getParameter("resource") == null
&& httpRequest.getParameter("graph") == null) {
String queryString = httpRequest.getQueryString();
logger.info("request from " + httpRequest.getRemoteAddr() + ": "
+ httpRequest.getRequestURI() + (queryString == null ? "" : '?' + queryString));
}
chain.doFilter(request, response);
}
public void destroy() {
}
}
You can add the following in the web.xml file of your webapp to log access to
"/monitoring":
<filter>
<filter-name>logmonitoring</filter-name>
<filter-class>mypackage.LogFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>logmonitoring</filter-name>
<url-pattern>/monitoring</url-pattern>
</filter-mapping>
Original comment by evernat@free.fr
on 20 Jul 2013 at 10:08
Original issue reported on code.google.com by
ConorWSu...@gmail.com
on 18 Jul 2013 at 7:00