user2071938
user2071938

Reputation: 2255

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

Upvotes: 1

Views: 1968

Answers (1)

wangyuntao
wangyuntao

Reputation: 847

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>

Upvotes: 2

Related Questions