如何使用 log4j 1.2.7 在单个日志文件中配置和同步两个 WAR 文件的日志?
我有多个 WAR 文件(WAR-A、WAR-B 和 WAR-C),我希望将其所有日志放入单个日志文件“ABC.log”中。我为每个 WAR 文件创建了三个具有相同配置的“log4j.xml”。现在,log4j 正在工作,但它以一种非常随意且无组织的方式写入所有日志。意味着它们的顺序不正确。
WAR-A 和 WAR-C 的日志出现在文件的开头,而 WAR-B 的日志出现在文件的末尾。理想情况下,它们应该按顺序排列。此外,新文件在达到定义的“MaxFileSize”时不会创建。
另一件事是,如果我从 WAR-B 中删除“log4j.xml”配置文件,那么 WAR-A 和 WAR-C 日志就会以正确的方式显示。但是,这样我就丢失了 WAR-B 日志,因为我删除了 log4j.xml。
我的 log4j 配置是:
<!-- Appenders -->
<appender name="RollingFileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="append" value="false" />
<param name="maxFileSize" value="500KB" />
<param name="maxBackupIndex" value="50" />
<param name="file" value="c:/logs/ABC.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{2}:%L - %m%n" />
</layout>
</appender>
<!-- Root Logger -->
<root>
<priority value="info" />
<appender-ref ref="RollingFileAppender" />
</root>
作为参考,我使用 Wildfly 9.0.2 作为我的应用程序服务器。请分享您的想法,我该如何解决这个问题。任何帮助将非常感激!
I have multiple WAR files (WAR-A, WAR-B and WAR-C) for which I want to have all logs into a single log file "ABC.log". I have created three "log4j.xml" with the same configurations for each WAR file. Now, the log4j is working but it is writing all the logs in a very haphazard and non-organized manner. Means they are not in proper sequence.
Logs of WAR-A and WAR-C are appearing at the start of the file while the logs of WAR-B are appearing at the end of the file. They should have to be in a sequence ideally. Also the new file is not creating up upon reaching the defined "MaxFileSize".
One more thing, if I remove the "log4j.xml" configuration file from WAR-B then WAR-A and WAR-C logs are appearing in right manner. But, in this way I'm losing the WAR-B logs coz I have removed the log4j.xml.
My log4j configurations are:
<!-- Appenders -->
<appender name="RollingFileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="append" value="false" />
<param name="maxFileSize" value="500KB" />
<param name="maxBackupIndex" value="50" />
<param name="file" value="c:/logs/ABC.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{2}:%L - %m%n" />
</layout>
</appender>
<!-- Root Logger -->
<root>
<priority value="info" />
<appender-ref ref="RollingFileAppender" />
</root>
For the reference, I am using Wildfly 9.0.2 as my application server. Please share your thoughts how I can fix this issue. Any help would be really appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论