Two instances of Tomcat on the same machine using the same log file

ぃ、小莉子 提交于 2019-12-12 02:26:16

问题


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?


回答1:


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>

From official docs,

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.



来源:https://stackoverflow.com/questions/42836175/two-instances-of-tomcat-on-the-same-machine-using-the-same-log-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!