What is the log4j2 equivalent of LevelRangeFilter in yaml?

1.2k views Asked by At

What is the log4j2 equivalent of this in yaml?

<filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMax" value="fatal"/>
            <param name="LevelMin" value="error"/>
            <param name="AcceptOnMatch" value="true"/>
        </filter>

Is this correct?

LevelRangeFilter:
   onMatch: accept
   minLevel: error
   maxLevel: fatal
1

There are 1 answers

0
Michael Krupp On BEST ANSWER

Just stumbled upon this myself. Here is a minimal log4j2.yaml file that sends all ERROR events to STDERR and everything else to STDOUT:

Configuration:
  # ...
  Appenders:
    Console:
      - name: STDOUT
        target: SYSTEM_OUT
        Filters:
          - LevelRangeFilter:
              maxLevel: TRACE
              minLevel: INFO
              onMatch: ACCEPT
              onMismatch: DENY
      - name: STDERR
        target: SYSTEM_ERR
        Filters:
          - LevelRangeFilter:
              maxLevel: ERROR
              minLevel: ERROR
              onMatch: ACCEPT
              onMismatch: DENY
  Loggers:
    Root:
      level: INFO
      AppenderRef:
        - ref: STDOUT
        - ref: STDERR

Be careful with the minLevel and maxLevel, as TRACE > INFO > ERROR in log4j2.