从Tomcat7中的访问日志中过滤出image/css/js请求
我试图从我的访问日志中过滤掉任何image/css/js请求。我创建了一个过滤器(LoggingFilter)并在server.xml中设置了ConditionInspect属性,但我必须错过一个步骤,因为对image/css/js文件的请求仍然显示在日志中。有没有人能给我一个提示,说明我遗漏了什么 这是密码- LoggingFilter.java从Tomcat7中的访问日志中过滤出image/css/js请求,tomcat,Tomcat,我试图从我的访问日志中过滤掉任何image/css/js请求。我创建了一个过滤器(LoggingFilter)并在server.xml中设置了ConditionInspect属性,但我必须错过一个步骤,因为对image/css/js文件的请求仍然显示在日志中。有没有人能给我一个提示,说明我遗漏了什么 这是密码- LoggingFilter.java public class LoggingFilter implements Filter { @Override public void i
public class LoggingFilter implements Filter
{
@Override
public void init(FilterConfig filterConfig) throws ServletException
{
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
chain.doFilter(request, response);
if(response.getContentType() != null)
{
if (response.getContentType().contains("image") ||
response.getContentType().contains("css") ||
response.getContentType().contains("javascript"))
{
request.setAttribute("doNotLog", "noLog");
}
}
}
@Override
public void destroy()
{
}
}
下面是我在web.xml中的内容
<filter>
<filter-name>LoggingFilter</filter-name>
<filter-class>com.shop.famos.filters.LoggingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoggingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
日志过滤器
com.shop.famos.filters.LoggingFilter
日志过滤器
/*
在tomcat设置中,我有-
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" conditionUnless="doNotLog" pattern="common"/>
顺便说一句,我用的是Tomcat7
另外,我想提到的是,我确实看到了这篇文章,文章中说,要实现更具体的过滤器,必须将“org.apache.catalina.valves.AccessLogValve”子类化。这是唯一的办法吗?或者可以使用我上面提到的过滤器来实现吗?最终找到了我遗漏的步骤。我从Amazon的“ApacheTomcat7”中找到了一本好书,这本书帮助我认识到Tomcat有自己的内置过滤器,可以用来检查和修改传入的请求。最初,我将过滤器作为web项目的一部分,这没有什么好处,因为我的过滤器需要位于服务器级别,以便访问日志可以看到我设置的请求属性 所以基本上我把编译好的类放在一个jar中,放在Tomcat的类路径中,把我的过滤器定义和映射放在Tomcat的web.xml文件中,重新启动Tomcat并转到我网站的主页,确保对js、图像或css文件的任何请求都不会出现在日志中