问题描述
是否有一些路径仅将日志消息写入"子"记录器,避免根记录器?根记录器正在被其他组件使用,因此无法降低其级别或禁用附加程序.谢谢
推荐答案
请使用 Log4j 可加性.
将 Log4j 记录器的可加性属性设置为 false,然后到达该记录器的日志消息将不会传播到父记录器.
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
通过上述配置,来自 com.demo.moduleone 的日志消息将仅发送到 moduleOneAppender,其余日志消息将发送到 rootFileAppender.
问题描述
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
推荐答案
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.