2017-04-13 38 views
0

我有這個log4j2.xml - 配置文件。 如何製作過濾器來記錄過濾器和Loglevel ERROR中的所有指定標記? 在我的curent配置中,它只記錄指定的標記,但不是ERROR s我該怎麼做?Marker和Loglevel的log4j2過濾器

<Configuration status="warn" name="MyAppx" packages=""> 
<Appenders> 
    <RollingFile append="true" name="MyFile" fileName="/tmp/app.log" filePattern="/home/flex/logusb/app-%d{MM-dd-yyyy}-%i.log.gz"> 
     <Filters> 
      <MarkerFilter marker="MARKER1" onMatch="ACCEPT" onMismatch="NEUTRAL"/> 
      <MarkerFilter marker="MARKER2" onMatch="ACCEPT" onMismatch="NEUTRAL"/> 
      <MarkerFilter marker="MARKER3" onMatch="ACCEPT" onMismatch="DENY"/ 
     </Filters> 

     <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} app  %-5level %-30notEmpty{[%marker]} - %msg%xEx - %class{36} %L %M%n"/> 
     <Policies> 
      <!--<TimeBasedTriggeringPolicy />--> 
      <SizeBasedTriggeringPolicy size="20 MB"/> 
     </Policies> 
    <DefaultRolloverStrategy max="100"/> 
    </RollingFile> 
</Appenders> 
<Loggers> 
    <AsyncRoot level="INFO" includeLocation="true"> 
     <AppenderRef ref="MyFile" /> 
    </AsyncRoot> 
</Loggers> 

+0

要登錄'ERROR'消息,即使該消息不包含任何標記? – wangyuntao

+0

@wangyuntao確切! – user2071938

回答

2

嘗試:

<Filters> 
    <MarkerFilter marker="MARKER1" onMatch="ACCEPT" onMismatch="NEUTRAL"/> 
    <MarkerFilter marker="MARKER2" onMatch="ACCEPT" onMismatch="NEUTRAL"/> 
    <MarkerFilter marker="MARKER3" onMatch="ACCEPT" onMismatch="NEUTRAL"/> 
    <ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/> 
</Filters> 
+0

就是這樣!謝謝! – user2071938

+0

不客氣! :-) – wangyuntao