-1

please consider the follwing snippet:

   <AsyncLogger name="com.example.Section" level="WARN" additivity="false">
        <AppenderRef ref="Logger1" />

   </AsyncLogger>

     <AsyncLogger name="com.example.Section2" level="INFO"/>

    <AsyncRoot level="ALL">
        <AppenderRef ref="Logger1" />
    </AsyncRoot>

Am I correct in assuming that Section1 will be logged at warn level. And Section2 at ALL level (not info)?

UPDATE: I meant warning level or above for Section1.

GC_
  • 448
  • 4
  • 23

1 Answers1

0

No, that is not correct.

Any events with a level of WARN or more specific (ERROR or FATAL) that are sent to the "com.example.Section" logger will be accepted by that logger and sent to its appenders. Since additivity is false for this logger events are not sent to any appenders of its ancestors.

Any events with a level of INFO or more specific (WARN, ERROR, FATAL) sent to the logger "com.example.Section2" will be accepted by that logger and sent to its appenders. Since additivity is true by default events accepted by this logger will go to the appenders of its ancestors as well, which would only be those of the root logger.

Any events that go to the root logger will be accepted and sent to its appenders regardless of log level since its level is set to ALL. As this is the root logger additivity does nothing, there are no ancestors of this logger.

The log4j2 manual has examples and explanations of additivity that can help you understand this as well. There are some other questions on stackoverflow about additivity that may also be helpful.

D.B.
  • 4,523
  • 2
  • 19
  • 39