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.