从多个应用程序/进程记录到单个日志文件 [英] Logging from multiple apps/processes to a single log file

查看:341
本文介绍了从多个应用程序/进程记录到单个日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用服务器(weblogic)都使用log4j登录网络共享上的同一文件。除此之外,我们将托管服务器中的所有Web应用程序记录到常见的error.log中。我无法想象这是一个好主意,但想听听一些专业人士的意见。我知道每个Web应用程序都有自己的类加载器,因此任何线程同步只发生在应用程序中。那么当多个进程开始聚合在一个日志文件上时会发生什么?我们可以期待散布的日志声明吗?性能问题?如何将多个Web应用程序记录到公共日志文件中?环境是Solaris。

Our app servers (weblogic) all use log4j to log to the same file on a network share. On top of this we have all web apps in a managed server logging errors to a common error.log. I can't imagine this is a good idea but wanted to hear from some pros. I know that each web app has its own classloader, so any thread synchronization only occurs within the app. So what happens when multiple processes start converging on a single log file? Can we expect interspersed log statements? Performance problems? What about multiple web apps logging to a common log file? The environment is Solaris.

推荐答案

对于没有同步对文件的写访问权限以及当然糟糕的编程习惯,这是一个非常糟糕的主意。它可能工作的唯一情况是附加到本地机器上的文件 - 每个人只是在文件末尾添加行。

This is generaly bad idea to have not synchronized write access to a file and certainly bad programming practice. The only case it might work is an append to a file on local machine - everybody just adds lines at the end of file.

但是,由于您的文件位于网络共享上,因此可能会很快变成垃圾。您没有告诉您正在使用哪个分布式文件系统,但对于NFS,您可以在open(2)手册页上找到以下说明:

But, since your file is on the network share, it will probably quickly turn into garbage. You didn't tell which distributed filesystem you are using, but for NFS you can find following explanation on open(2) man page:


O_APPEND
文件以追加模式打开。在每次write()之前,文件偏移量
位于文件的末尾,
就像使用lseek()一样。如果多个进程一次将数据
附加到文件,则O_APPEND可能会导致
到NFS文件系统上损坏的文件
。这是因为NFS
不支持附加到文件
所以客户端内核必须模拟
它,如果没有比赛
条件就无法完成。

O_APPEND The file is opened in append mode. Before each write(), the file offset is positioned at the end of the file, as if with lseek(). O_APPEND may lead to corrupted files on NFS file systems if more than one process appends data to a file at once. This is because NFS does not support appending to a file, so the client kernel has to simulate it, which can't be done without a race condition.

当然这是C,但由于Java是用C实现的,所以它不能做得更好(至少不是系统调用) : - ))。

Of course this is C, but since Java is implemented in C it cannot do any better than that (at least not with regard to system calls:-)).

这篇关于从多个应用程序/进程记录到单个日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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