Logger Additivity Control¶
In logging frameworks such as Log4j2, logger additivity determines whether a given logger should propagate its log events to the parent logger.^[600-developer-java-3-party-java-log4j2.md]
By default, logging follows a hierarchical structure where events bubble up to ancestors. However, this propagation can be explicitly configured to be false, which prevents log events from being passed up the chain.^[600-developer-java-3-party-java-log4j2.md]
Configuration¶
In XML configuration, additivity is controlled via the additivity attribute within a <Logger> tag.^[600-developer-java-3-party-java-log4j2.md] When configured, the logger will strictly adhere to its own defined appenders without inheriting output directives from higher-level loggers.^[600-developer-java-3-party-java-log4j2.md]
<Logger name="bolt" additivity="false">
<AppenderRef ref="bolt"/>
</Logger>
Use Cases¶
Disabling additivity is essential when developers want to isolate specific log streams to dedicated appenders, such as separate log files for different components.^[600-developer-java-3-party-java-log4j2.md] For example, in a system with "main", "bolt", and "spout" loggers, setting additivity="false" ensures that the "bolt" logger writes only to the "bolt" appender and not to the console or the "main" log file.^[600-developer-java-3-party-java-log4j2.md]
Sources¶
^[600-developer-java-3-party-java-log4j2.md]