简体   繁体   中英

log4j2: parent logger level lower than child logger

I am not sure if this has been answered before. I saw cases with root but I am not sure if the same is applicable to my scenario as well. This is my sample log file. Consider Case 1:

<logger name="com.abc" level="warn" additivity="false">
  <appender-ref ref="Default"/>
</logger>
<logger name="com.abc.xyz" level="debug" additivity="false">
  <appender-ref ref="Default"/>
</logger>
<root level="error">
  <appender-ref ref="Console"/>
</root>

In the above case, the child package has a lower debug level than the parent. So when I run my application, I get the logs from the package "com.abc.xyz" with debug level and the rest of the application at warn level. However when the same is reversed, ie consider Case 2:

<logger name="com.abc" level="debug" additivity="false">
  <appender-ref ref="Default"/>
</logger>
<logger name="com.abc.xyz" level="warn" additivity="false">
  <appender-ref ref="Default"/>
</logger>
<root level="error">
  <appender-ref ref="Console"/>
</root>

In the above case, the child package logger level is not honored and all the logs from the package "com.abc" are logged at debug level. Is there any configuration that can be used to ensure that the child package logger level is given more precedence over parent level?

Works for me.

The important bit is that the child logger must have additivity="false" , but you got that right.

There must be something more to your issue, something else is causing this. Either you're not correctly matching the loggers, or there's more configuration than you show that overrides the part shown.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM