Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j2 threshold for consoleappender

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 ?

like image 366
user3207875 Avatar asked Jan 02 '17 13:01

user3207875


People also ask

What is Log4j2 ConsoleAppender?

Log4j2 ConsoleAppender appends the log events generated by application into the System. out or System.

What is threshold in log4j?

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.

What is root level in Log4j2?

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.


1 Answers

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>
like image 148
Remko Popma Avatar answered Oct 16 '22 13:10

Remko Popma