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