问题描述
我最近遇到了一个问题,我的日志文件没有像我的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>
根据官方文档
这篇关于使用同一日志文件的同一台机器上的Tomcat的两个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!