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 ?
Log4j2 ConsoleAppender appends the log events generated by application into the System. out or System.
Threshold=WARN ... To understand what it is, you should know that: The levels of logging increase when retrieving to the leftmost: TRACE, DEBUG, INFO, WARN, ERROR and FATAL. Minimum level logging which logger accepts from application. Minimum level logging on appender which decides what will be written.
Configuration: the root element of a log4j2 configuration file; the status attribute represents the level at which internal log4j events should be logged. Appenders: this element contains a list of appenders; in our example, an appender corresponding to the System console is defined.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With