Logging from multiple apps/processes to a single log file

后端 未结 7 887
时光取名叫无心
时光取名叫无心 2020-12-15 08:55

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 erro

相关标签:
7条回答
  • 2020-12-15 09:23

    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.

    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 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.

    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:-)).

    0 讨论(0)
提交回复
热议问题