在下面的示例中,在log4j配置文件中有如下一行:
<Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
除了follow="true"之外,我理解了这行中的所有内容,我在官方网站上阅读了这个特定参数的描述:。我也尝试在其他网站搜索,但没有结果。
描述如下:

这个描述让我感到困惑,他们所说的“荣誉重新分配……”是什么意思,它的目的是什么,如果我把它改为false会发生什么。
发布于 2022-02-17 12:40:52
System.out属性不是只读的,可以通过System#setOut重新分配.使用follow="true",附录将发送消息到当前的值System.out,而使用follow="false"日志将发送到System.out的原始值。
您可以使用以下方法测试这两种行为:
// 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 很少重新分配。
https://stackoverflow.com/questions/71158063
复制相似问题