Migrating from log4j 1.2 to log4j 2: LevelRangeFilter
Asked Answered
L

3

6

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>
Lugansk answered 24/7, 2014 at 11:33 Comment(0)
L
11

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>
Lugansk answered 24/7, 2014 at 11:33 Comment(2)
The bitfish link you mentioned is dead!Morbidity
what about doing the same in .properties file instead of xmlMelleta
H
1

We can use below Filter.

<LevelRangeFilter minLevel="DEBUG" maxLevel="DEBUG" onMatch="ACCEPT" onMismatch="DENY"/>
Howlend answered 27/12, 2021 at 11:10 Comment(0)
R
0

Following appender configurations help to separate writing to stdout and stderr (useful e.g. within eclipse whose console displays the stderr in red).

log4j2 V2.19

<Console name="stdout" target="SYSTEM_OUT">
   <PatternLayout ...
   <LevelRangeFilter minLevel="INFO" maxLevel="ALL" onMatch="ACCEPT" onMismatch="DENY"/>
</Console>
<Console name="stderr" target="SYSTEM_ERR">
   <PatternLayout ...
   <LevelRangeFilter minLevel="FATAL" maxLevel="WARN" onMatch="ACCEPT" onMismatch="DENY"/>
</Console>

One remark on the min/max-Level property: it's somehow contra-intuitive, since FATAL is the smallest, ALL is the highest level.

Rovelli answered 21/6, 2023 at 13:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.