Search code examples
filterlog4jlog4j2

Migrating from log4j 1.2 to log4j 2: LevelRangeFilter


What is the log4j 2 equivalent of the following log4j 1.2 configuration?

<filter class="org.apache.log4j.varia.LevelRangeFilter">
    <param name="LevelMin" value="DEBUG" />
    <param name="LevelMax" value="INFO" />
</filter>

Solution

  • Instead of having to create your own filter (http://bitfish.eu/java/log4j-2-multiple-appenders-with-different-log-levels/) you can simply use a composite filter with two ThresholdFilters:

    <Filters>
        <ThresholdFilter level="DEBUG"/>
        <ThresholdFilter level="WARN" onMatch="DENY" onMismatch="NEUTRAL"/>
    </Filters>