我在log4j2.xml中使用正则表达式过滤器(.asterisk User-Agent = BigIP Prober.asterisk)来过滤特定的日志消息(level = INFO)并使用滚动随机文件appendar将其打印在文件中。这个过滤器适用于单行日志消息,当我尝试对多行日志消息执行相同操作时,它只获取正则表达式行而不是整个消息。
日志消息:
INFO 2016-08-09 08:05:00 TraceId=536906802.1470654766130752941 [qtp1386518493-290] org.mule.api.processor.LoggerMessageProcessor: - Jetty Connector Message - Port configured for it -
org.mule.DefaultMuleMessage{
Content-Length=558,
User-Agent=BigIP Prober,
Connection=keep-alive,
Accept-Encoding=gzip,
deflate,
http.method=POSThttp.query.params={}}
代码:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration >
<Properties>
<Property name="logpath">${env:MULE_BASE}/logs</Property>
<Property name="appname">${env:MULE_APP}</Property>
</Properties>
<Appenders>
<RollingRandomAccessFile name="RollingRandomAccessFile" fileName="${logpath}/1.log"
filePattern="${logpath}/1-%d{yyyy-MM-dd}-%i.log">
<PatternLayout pattern="%-5p %d{yyyy-MM-dd HH:mm:ss} TraceId=%X{svTraceId} [%t] %c:%L - %m%n" />
<RegexFilter regex=".*User-Agent=BigIP Prober.*" onMatch="DENY" onMismatch="ACCEPT"/>
<Policies>
<OnStartupTriggeringPolicy />
<SizeBasedTriggeringPolicy size="100MB"/>
<TimeBasedTriggeringPolicy />
</Policies>
<DefaultRolloverStrategy max="20" fileIndex="min"/>
</RollingRandomAccessFile >
<RollingRandomAccessFile name="PerfRollingRandomAccessFile" fileName="${logpath}/2.log"
filePattern="${logpath}/2-%d{yyyy-MM-dd}-%i.log">
<PatternLayout pattern="%-5p %d{yyyy-MM-dd HH:mm:ss} TraceId=%X{svTraceId} [%t] %c:%L - %m%n" />
<RegexFilter regex=".*User-Agent=BigIP Prober.*" onMatch="ACCEPT" onMismatch="DENY"/>
<Policies>
<OnStartupTriggeringPolicy />
<SizeBasedTriggeringPolicy size="100MB"/>
<TimeBasedTriggeringPolicy />
</Policies>
<DefaultRolloverStrategy max="20" fileIndex="min"/>
</RollingRandomAccessFile >
</Appenders>
<Loggers>
<Logger name="org.mule.api.processor.LoggerMessageProcessor" level="DEBUG"/>
<Logger name="org.mule.api.processor.LoggerMessageProcessor" level="INFO" >
<AppenderRef ref="PerfRollingRandomAccessFile" />
<AppenderRef ref="RollingRandomAccessFile" />
</Logger>
<Logger name="com.bac" level="DEBUG" />
<Logger name="com.bac.gwb.credit.lda.transformer.ReferenceValueTranslator" level="DEBUG" />
<Root level="INFO">
<AppenderRef ref="RollingRandomAccessFile" />
</Root>
</Loggers>
</Configuration>