log4j2 threshold for consoleappender
Asked Answered
M

2

9

How to set threshold value for ConsoleAppender in new log4j2 using xml file. Usually we do it in log4j 1.x in the below way.

Ref link: Log4j - priority value and param name concept explanation

How to set it in log4j 2.x ?

Monolatry answered 2/1, 2017 at 13:0 Comment(0)
D
10

You can set a log level on the AppenderRef:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp" packages="">
  <Appenders>
    <Console name="STDOUT" target="SYSTEM_OUT">
      <PatternLayout pattern="%m%n"/>
    </Console>
    <File name="MyFile" fileName="logs/app.log">
      <PatternLayout>
        <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
      </PatternLayout>
    </File>
  </Appenders>
  <Loggers>
    <Root level="trace">
      <AppenderRef ref="STDOUT" level="warn"/>
      <AppenderRef ref="MyFile"/>
    </Root>
  </Loggers>
</Configuration>
Draftee answered 3/1, 2017 at 0:38 Comment(0)
M
1

You can use filter to replace the

<param name="Threshold" value="trace" />

with

<Filter type="ThresholdFilter" level="trace"/>
Merrygoround answered 5/1, 2022 at 8:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.