gpt4 book ai didi

java - 如何禁用输出到 log4j.rootLogger?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:51:41 25 4
gpt4 key购买 nike

我想在记录到文件时禁用到控制台的输出。请参阅下面的配置文件:

log4j.rootLogger=info,stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L --- %m%n

log4j.category.FileLog=info,R
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=E:\\temp\\FileLog
log4j.appender.R.Append = true
log4j.appender.R.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%m[%d{MM-dd HH:mm:ss}]%n

当我使用时:

Logger.getLogger("FileLog").info("LogText-FileLog");

此日志也打印到 stdout,我该如何禁用它?

最佳答案

您可以使用 `log4j.additivity.FileLog = false,这是您正在寻找的“标志”。

来自official log4j documentation :

The output of a log statement of logger C will go to all the appenders in C and its ancestors. This is the meaning of the term "appender additivity".

However, if an ancestor of logger C, say P, has the additivity flag set to false, then C's output will be directed to all the appenders in C and its ancestors upto and including P but not the appenders in any of the ancestors of P.

Loggers have their additivity flag set to true by default.

从根记录器中删除“stdout”(如其他答案中所建议的那样)可能不是解决方案,因为我想在某些情况下您仍然对控制台日志感兴趣。

关于java - 如何禁用输出到 log4j.rootLogger?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7513463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com