简体   繁体   中英

log4j2 filter for Marker and Loglevel

I have this log4j2.xml -Configuration file. How can I make a filter to log all the Specified markers in the Filter AND Loglevel ERROR ? In my curent configuration it only logs the Specified Markers but not ERROR s how could I do that?

<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>

Try:

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM