gpt4 book ai didi

java - 我可以使用多个 Play Server 实例来记录磁盘上的同一文件吗?

转载 作者:行者123 更新时间:2023-12-02 07:01:09 25 4
gpt4 key购买 nike

我在多个应用程序中使用 Play 文件记录器,如下所示:

Class1.java
private static ALogger logger = Logger.of("myAppLogger");
public void someMethodOfClass1() {
logger.info("This is Class1");
}

Class2.java
private static ALogger logger = Logger.of("myAppLogger");
public void someMethodOfClass2() {
logger.info("This is Class2");
}

Class3.java
Class4.java

等等

现在,如果我在同一台计算机上运行多个 Play 服务器实例(或一个服务器实例和一个带有 new play.api.Application 的实例来运行批处理脚本),它是否有效且推荐将多个服务器实例与一个文件记录器一起使用?

最佳答案

Play 框架使用 Logback 日志框架。

我建议你应该看看Logback的文档File Appender 。根据文档,FileAppender 支持默认设置为 false 的谨慎模式。

In prudent mode, FileAppender will safely write to the specified file, even in the presence of other FileAppender instances running in different JVMs, potentially running on different hosts. The default value for prudent mode is false.

但同一页面警告:

Prudent mode relies on exclusive file locks. Experiments show that file locks approximately triple (x3) the cost of writing a logging event. On an "average" PC writing to a file located on a local hard disk, when prudent mode is off, it takes about 10 microseconds to write a single logging event. When prudent mode is on, it takes approximately 30 microseconds to output a single logging event. This translates to logging throughput of 100'000 events per second when prudent mode is off and approximately 33'000 events per second in prudent mode.

文档中并不清楚如果您在审慎模式关闭时尝试从多个 jvm 登录会发生什么情况。

关于java - 我可以使用多个 Play Server 实例来记录磁盘上的同一文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16650308/

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