I want to use RegexFilter (https://logging.apache.org/log4j/2.x/manual/filters.html#RegexFilter) in order to filter URLs. But in order to do so i need to config the regex pattern with Pattern.DOTALL
flag. How do I config the RegexFilter to construct his pattern with this flag ?
I tried this :
<RegexFilter regex=".*https://[-A-Za-z0-9+&@#/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%=~_()|].*" onMatch="DENY" onMismatch="ACCEPT" PatternFlags="DOTALL"/>
But the PatternFlags
is ignored.
Looking at the RegexFilter code, It does read the PatternFlags property :
@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);
}
}