gpt4 book ai didi

apache - 不要记录 tomcat localhost_access_log 的特定 url 模式

转载 作者:行者123 更新时间:2023-11-28 22:47:05 25 4
gpt4 key购买 nike

我想知道是否有任何方法可以在 apache 访问日志中进行条件记录。来自 $CATALINA_HOME/conf/server.xml 的 AccessLogValve

    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%{X-Forwarded-For}i %h %l %u %t &quot;%r&quot; %s %b" />
<Context path="" docBase="/usr/share/tomcat8/webapps/ROOT/www" reloadable="true" crossContext="true"/>

例如:我不想记录传递敏感信息的 URL/email/somesensitve 信息。有什么办法可以在 server.xml 或任何其他方式中指定它。

这就是我们可以在 apache httpd 中指定的方式 https://www.howtoforge.com/setenvif_apache2SetEnvIf Request_URI "^/email/token$"dontlog

最佳答案

解决方案是在Server.xml中使用定义条件属性

<Valve className="org.apache.catalina.valves.FastCommonAccessLogValve" directory="logs" 
prefix="access_log." suffix=".txt" pattern="common" resolveHosts="false" condition="donotLog" />

定义一个 RequestFilter 实现 Filter

public class RequestFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
try {
if ( request instanceof HttpServletRequest){
HttpServletRequest httpServletRequest = (HttpServletRequest)request;
String url = getFullURL(httpServletRequest);
//initialize pattern only once
if (pattern == null){
String fPattern = filterConfig.getInitParameter("donotLogPattern");
LOGGER.info("FilterPattern {}",fPattern);
pattern = Pattern.compile(fPattern);
}
//If find a pttern then set do not log condition
if (pattern.matcher(url).find()){
LOGGER.info("Setting donotLog attribute");
request.setAttribute("donotLog","true");
}
}
...

在 web.xml 中定义这个 init-params

 <filter>
<filter-name>requestFilter</filter-name>
<filter-class>com.netgear.hms.config.RequestFilter</filter-class>
<init-param>
<param-name>logParam</param-name>
<param-value>donotLog</param-value>
</init-param>
<init-param>
<param-name>donotLogPattern</param-name>
<param-value>creditCard|passowrd</param-value>
</init-param>

关于apache - 不要记录 tomcat localhost_access_log 的特定 url 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56014578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com