Java log4j2 logger levels aren't being followed

Deadly 提交于 2019-12-02 09:14:18

The issue you're having is due to additivity being true by default. Your tutorial is misleading in that it says:

By default log4j2 logging is additive. It means that all the parent loggers will also be used when a specific logger is used.

In fact it does not mean that all parent loggers will be used, it means all of the appenders of parent loggers will be used. You should read the log4j2 manual, particularly the section on additivity.

In the additivity section of the manual, there is an example with some explanation after it:

Notice that the trace messages from com.foo.Bar appear twice. This is because the appender associated with logger com.foo.Bar is first used, which writes the first instance to the Console. Next, the parent of com.foo.Bar, which in this case is the root logger, is referenced. The event is then passed to its appender, which also writes to the Console, resulting in the second instance. This is known as additivity.

With additivity set to true (as it is by default) any event accepted by a child logger is passed to the appenders of all parent loggers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!