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 ?

2 Answers 2

9

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

You can use filter to replace the

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

with

<Filter type="ThresholdFilter" level="trace"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.