我的日志中有以下几行我想排除,所以我想使用RegexFilter
这样做:
[INFO ] 2018-05-20 14:52:15.993 [qtp22844606-20] TimingFilter -
Request time: 16 ms
[INFO ] 2018-05-20 14:52:18.998 [qtp22844606-17] TimingFilter -
Request time: 15 ms
[INFO ] 2018-05-20 14:52:22.001 [qtp22844606-20] TimingFilter -
Request time: 0 ms
[INFO ] 2018-05-20 14:52:24.992 [qtp22844606-17] TimingFilter -
Request time: 0 ms
我的配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<RegexFilter regex=".*TimingFilter.*" useRawMsg="true" onMatch="DENY" onMismatch="ACCEPT"/>
<PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Root level="info" additivity="false">
<appender-ref ref="console" />
</Root>
</Loggers>
</Configuration>
当切换“ACCEPT”和“DENY”时,没有消息通过,因此 RegexFilter 本身似乎被拾取。我也尝试过“\bTimingFilter\b”、“.*\bTimingFilter\b.*”但没有成功。
我正在使用 Log4J 2.11。
你能提示我做错了什么吗?我检查了所有其他RegexFilter
相关问题在这里以及其他网站(这是我尝试过的正则表达式模式的建议的地方),但似乎没有任何效果。
我还检查了模式https://regex101.com/ https://regex101.com/对照我的日志,它们匹配正确。
This happens because you have useRawMsg="true"
switch it to useRawMsg="false". See the log4j2 manual https://logging.apache.org/log4j/2.x/manual/filters.html#RegexFilter:
如果 true 将使用未格式化的消息,否则将使用格式化的消息
将使用消息。默认值为 false。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)