加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – log4j将所有日志输出引导到stdout,即使不是这样

发布时间:2020-12-14 05:27:26 所属栏目:Java 来源:网络整理
导读:在我的log4j.properties我有: log4j.rootLogger=DEBUG,stdoutlog4j.logger.notRootLogger=DEBUG,somewhereelse 附加信号stdout和athereelse都配置正确,stdout写入控制台和某个文件的写入. 在我的每个类的代码中,我设置: static Logger log = Logger.getLog
在我的log4j.properties我有:
log4j.rootLogger=DEBUG,stdout

log4j.logger.notRootLogger=DEBUG,somewhereelse

附加信号stdout和athereelse都配置正确,stdout写入控制台和某个文件的写入.

在我的每个类的代码中,我设置:

static Logger log =  Logger.getLogger("notRootLogger);

^当我不想要的东西去控制台.

-要么-

static Logger log = Logger.getRootLogger();

当我做的

在log4.properties中必须做什么才能阻止写入toRootLogger的东西以stdout结尾?是否有某种继承,无论根记录器写入哪里,需要关闭某种方式?

我不想单独为每个单独的类配置一个记录器,我只想登录到控制台.

解决方法

你需要设置additivity = false,IIRC.从 log4j manual:

Each enabled logging request for a
given logger will be forwarded to all
the appenders in that logger as well
as the appenders higher in the
hierarchy. In other words,appenders
are inherited additively from the
logger hierarchy. For example,if a
console appender is added to the root
logger,then all enabled logging
requests will at least print on the
console. If in addition a file
appender is added to a logger,say C,
then enabled logging requests for C
and C’s children will print on a file
and on the console. It is possible to
override this default behavior so that
appender accumulation is no longer
additive by setting the additivity
flag to false.

尝试这个:

log4j.rootLogger=DEBUG,stdout
log4j.logger.notRootLogger=DEBUG,somewhereelse
log4j.additivity.notRootLogger=false

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读