使用同一日志文件的同一台机器上的Tomcat的两个实例 [英] Two instances of Tomcat on the same machine using the same log file

查看:245
本文介绍了使用同一日志文件的同一台机器上的Tomcat的两个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近遇到了一个问题,我的日志文件没有像我的log4j配置中所定义的那样滚动.我发现罪魁祸首是我有两个实例Tomcat运行同一个应用程序,而这两个实例都拥有相同的日志文件,因此任何一个都不能因为另一个而将其翻转.

I recently had an issue where my log files were not rolling over like they were supposed to as defined in my log4j config. I figured out that the culprit was that I have two instances Tomcat running the same app which both had a hold of the same log file, so neither one could roll it over because of the other one.

但是,我仍然想使用相同的日志文件.我使用两个实例进行负载平衡,每个实例都有一个日志文件会很烦人.

However, I would still like to use the same log file. I use two instances for load balancing and it would be annoying to have a log file for each instance.

有什么办法可以做到这一点?还是我注定要有多个日志文件?

Is there any way I can do this? Or am I doomed to have multiple log files?

推荐答案

建议对多个应用程序使用相同日志文件因为,

I would not recommend to use same log file for multiple applications.Because,

  • 很难读取日志文件.
  • 这会影响性能.
  • it will be difficult to read log file.
  • it will impact performance.

但是,您可以通过使用来自以下位置的"审慎"标志来实现此目的重新登录如下.

However, you can achieve this by using 'prudent' flag from logback as below.

<appender name="FILE_PRUDENT" class="ch.qos.logback.core.FileAppender">
    <file>logs/test.log</file>
    <prudent>true</prudent>
</appender>

根据官方文档

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

这篇关于使用同一日志文件的同一台机器上的Tomcat的两个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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