首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >log4j ConsoleAppender跟随参数的用途是什么?

log4j ConsoleAppender跟随参数的用途是什么?
EN

Stack Overflow用户
提问于 2022-02-17 12:21:32
回答 1查看 839关注 0票数 0

在下面的示例中,在log4j配置文件中有如下一行:

<Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">

除了follow="true"之外,我理解了这行中的所有内容,我在官方网站上阅读了这个特定参数的描述:。我也尝试在其他网站搜索,但没有结果。

描述如下:

这个描述让我感到困惑,他们所说的“荣誉重新分配……”是什么意思,它的目的是什么,如果我把它改为false会发生什么。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-17 12:40:52

System.out属性不是只读的,可以通过System#setOut重新分配.使用follow="true",附录将发送消息到当前的System.out,而使用follow="false"日志将发送到System.out的原始值。

您可以使用以下方法测试这两种行为:

代码语言:javascript
复制
      // This performs automatic initialization
      final Logger logger = LogManager.getLogger(Log4j2Test.class);
      // System.out is attached to the JVM's `stdout`
      logger.warn("Sent to 'stdout'");
      // Reassignement of System.out
      System.setOut(new PrintStream(new File("file.log")));
      // System.out is attach to the file 'file.log'
      logger.warn("Sent to 'file.log'");

从实际角度来看,follow="true"的性能比follow="false"差,而System.out is 很少重新分配

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71158063

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档