59

In simple terms what is the result of making additivity="true" or additivity="false" when adding a Log4j configuration for a specific class like this?

<Logger name="com.mypage.glass.TryWindow" level="INFO" additivity="true">
  <AppenderRef ref="console"/>
  <AppenderRef ref="file"/>
</Logger>
Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
user3433510
  • 593
  • 1
  • 4
  • 4

1 Answers1

70

By default, a logger inherits the appenders from its ancestors. By setting additivity="false", you prevent this behaviour.

In your example, there may be appenders associated with com.mypage.glass or com.mypage or even the root logger that would be inherited if you don't set that property to false.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
  • 2
    But what happens on the actual file...meaning if i make it true or false what will happen on the outputed log on the file or console? – user3433510 Mar 27 '14 at 15:44
  • 9
    @user3433510 Suppose your root logger has a ConsoleAppender configured, so that all INFO messages get printed to the console. If you have `additivity="true"` (the default), your `com.mypage.glass.TryWindow` logger will also output to the console. If you wanted to prevent this, you could set `additivity="false"`. If any of these terms are confusing, I suggest you read the [short introduction to log4j](https://logging.apache.org/log4j/1.2/manual.html). – Duncan Jones Mar 27 '14 at 15:50
  • 3
    Adding a a property "inheritAppenders" would have been to simple... THX! – eventhorizon Dec 01 '21 at 09:39