我想使用RegexFilter(https://logging.apache.org/log4j/2.x/manual/filters.html#RegexFilter)来过滤URL。但是,为此,我需要使用Pattern.DOTALL
标志配置正则表达式模式。如何配置RegexFilter以使用此标志构造其模式?
我尝试了这个:
<RegexFilter regex=".*https://[-A-Za-z0-9+&@#/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%=~_()|].*" onMatch="DENY" onMismatch="ACCEPT" PatternFlags="DOTALL"/>
但是PatternFlags
被忽略。
查看RegexFilter代码,它确实读取了PatternFlags属性:
@PluginFactory
public static RegexFilter createFilter(@PluginAttribute("regex") String regex, @PluginElement("PatternFlags") String[] patternFlags, @PluginAttribute("useRawMsg") Boolean useRawMsg, @PluginAttribute("onMatch") Result match, @PluginAttribute("onMismatch") Result mismatch) throws IllegalArgumentException, IllegalAccessException {
if (regex == null) {
LOGGER.error("A regular expression must be provided for RegexFilter");
return null;
} else {
return new RegexFilter(useRawMsg.booleanValue(), Pattern.compile(regex, toPatternFlags(patternFlags)), match, mismatch);
}
}