Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j2 configuration - What happens if AppenderRef not set for logger?

What happens if I don't explicitly set the AppenderRef for the logger config in log4j2.xml ? Would it use all the appenders by default ?

. .

<Logger name="com.package1" level="error"/>

<Root level="error">
  <AppenderRef ref="LOGFILE"/>
  <AppenderRef ref="CONSOLE"/>
</Root>

. .

like image 354
Sumalatha Abhishek Avatar asked Jun 28 '16 21:06

Sumalatha Abhishek


2 Answers

A logger calls all appenders for which it has an AppenderRef, and after that it delegates to its parent (the root logger in your example).

You can prevent it from calling its parent by configuring additivity="false". In that case the level configured on the logger may prevent the event from being logged. This is commonly used to filter out very verbose logging from certain packages.

like image 143
Remko Popma Avatar answered Nov 14 '22 23:11

Remko Popma


In addition to Remko's answer, if the Logger with additivity set to false or the root Looger has no appender references then the event will be ignored.

like image 28
rgoers Avatar answered Nov 14 '22 21:11

rgoers