简体   繁体   English

Log 4j常用日志文件用于多个Web应用程序?

[英]Log 4j common log file for multiple web applications?

I've 2 webapplications, want to log the log messages of these two web apps into only one log file. 我有2个web应用程序,想要将这两个Web应用程序的日志消息记录到一个日志文件中。 I tried this scenario, facing the issue as "If one web app logs the message into log, the second web app is not able log the message into log file". 我尝试了这个场景,面对的问题是“如果一个Web应用程序将消息记录到日志中,则第二个Web应用程序无法将消息记录到日志文件中”。 If I stop the server, the second app is able to log.Any help? 如果我停止服务器,第二个应用程序能够登录。任何帮助?

writing to the same file from multiple independant processes is a bad idea - only one of them can get a file lock, as evident from your issues. 从多个独立进程写入同一文件是一个坏主意 - 只有其中一个可以获得文件锁定,从您的问题可以看出这一点。

what you need is a centralized logging server and have all of your applications log to that server over the network. 您需要的是集中式日志服务器,并让您的所有应用程序通过网络登录到该服务器。 see this question 看到这个问题

You can use Log4J's SocketAppender for that, which is much cleaner - an example can be found in this article: log4j: How to use SocketAppender . 您可以使用Log4J的SocketAppender ,它更清晰 - 本文中可以找到一个示例: log4j:如何使用SocketAppender

To be honest it is a bit overkill compared to having two independent logfiles for your processes. 说实话,与为您的进程提供两个独立的日志文件相比,这有点过分。

Btw. 顺便说一句。 your approach might have problems on distributed filesystems (eg NFS) - don't mix logfiles. 您的方法可能在分布式文件系统 (例如NFS) 存在问题 - 不要混合使用日志文件。

Hope that helped a bit. 希望有所帮助。 *Jost *约斯特

It is not good idea to put logging of two different applications to common log. 将两个不同的应用程序的日志记录放到公共日志中并不是一个好主意。 Logging module lock the log file for writing. 记录模块锁定日志文件以进行写入。 if other application is trying to access the same log, it wont get the lock. 如果其他应用程序试图访问相同的日志,它将无法获得锁定。 I would avoid such things. 我会避免这样的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM