How to avoid writing messages to the root logger in log4j v.1

≡放荡痞女 提交于 2020-01-06 02:37:05

问题


Is some path to write log messages only to the 'child' logger, avoiding root logger? The root logger is using by other components, so there is no ability to decrease it's level or disable appender. thanks


回答1:


Please use Log4j additivity.

Set the additivity property of a Log4j logger to false and then the log messages which are coming to that logger will not be propagated to parent loggers.

Log4j configuration file:

log4j.category.com.demo.moduleone = INFO, moduleOneFileAppender
log4j.additivity.com.demo.moduleone = false
log4j.category.com.demo.moduletwo = INFO, moduleTwoFileAppender
log4j.additivity.com.demo.moduletwo = false
log4j.rootLogger = INFO, rootFileAppender

With the above configuration, the log messages from the com.demo.moduleone will go to the moduleOneAppender only and the rest of the log messages will go to the rootFileAppender.



来源:https://stackoverflow.com/questions/31059085/how-to-avoid-writing-messages-to-the-root-logger-in-log4j-v-1

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