java - Log4j RegexFilter,如何配置 PatternFlags?
问题描述
我想使用 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);
}
}
解决方案
推荐阅读
- angular - 角度 e2e 测试不必要地等待
- php - 在新选项卡上打开图像
- javascript - 如何通过按帐户/ID/类别分组来对值求和?
- javascript - 检查 JS 变量是否不超过一个值的最佳方法?
- linux - 如何使用 mmcli(ModemManager DBus 驱动的 Linux 守护程序 API)将 sim 号码列入白名单
- rotation - 用鼠标拖动、调整大小和旋转
- docker - 为什么我不能附加到 mariadb 的 docker 容器?
- postgresql - postgres 11:禁止缓存表
- python - ValueError:形状 (None, 1) 和 (None, 5) 不兼容
- java - 在 Java 中打印出带有时区的本地化日期