Log4j vs Logback:并发写入同一个日志? [英] Log4j vs Logback: concurrent writing to same log?

查看:1033
本文介绍了Log4j vs Logback:并发写入同一个日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一个tomcat上运行了几个Web应用程序。

I have several web applications running on the same tomcat.

我有两个问题:

1 - 通过搜索,我了解到当存在多个应用程序时,登录同一文件可能会产生一些问题。这是在同一个Web服务器上运行的多个应用程序的情况吗?当使用默认的stdout输出时,这也是正确的吗?

1- By searching, I understood that when multiple applications are present, logging into the same file might make some problems. Is that the case for multiple applications running on the same web server? Is that also correct when default stdout output is used?

2-在Logback库中有一个谨慎的模式:

2- In Logback library there is a prudent mode:

在谨慎模式下,即使存在可能在不同主机上运行的不同JVM中运行的其他FileAppender实例,FileAppender也会安全地写入指定文件。 prudent模式的默认值为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.

我想知道使用Logback是否只对多个JVM有利,或者对于在同一网络上运行的多个应用程序也有利服务器?如果没有,在这方面是否与log4j相同?

I want to know if using Logback is only favorable on multiple JVMs or it is also advantageous for multiple we applications running on the same web server? If not, is it identical to log4j in this aspect?

谢谢

推荐答案

在log4j和logback中,如果多个 FileAppender 实例写入同一个日志文件,则所述日志文件成为风险腐败。在同一JVM或不同JVM上运行的 FileAppender 实例是否无关紧要,即损坏的风险是相同的。

In both log4j and logback if multiple FileAppender instances write to the same log file, there is a high risk for the said log file becoming corrupt. Whether the FileAppender instances run on the same JVM or different JVMs is irrelevant, i.e. the risk of corruption is the same.

如文档中所述,在谨慎模式 logback的 FileAppender 将避免损坏,即使存在其他 FileAppender 实例相同或不同的JVM,可能在不同的主机上运行。默认情况下,谨慎模式被禁用。

As mentioned in the docs, in prudent mode logback's FileAppender will avoid corruption, even in the presence of other FileAppender instances running in the same or different JVMs, potentially running on different hosts. By default, prudent mode is disabled.

控制台不能被破坏所以问题没有实际意义。

The console cannot be corrupted so the question is moot.

这篇关于Log4j vs Logback:并发写入同一个日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆