Take the 2-minute tour ×

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.

share|improve this question
Have you experienced any actual log corruption? I would be surprised if the answer is no, but otherwise I can't imagine why you are asking the question. –  Yishai Apr 7 '10 at 21:52
No log corruption yet, that I'm aware of. I'm asking because I couldn't believe they had set it up this way and wanted some feedback to confirm my suspicions. –  Andrew Apr 7 '10 at 22:06
I should have clarified that a single log file is not a requirement; it was more design by coincidence. A few have mentioned the proper technique for a single log file is to use a network log service, or the application's server log service for per server logging. –  Andrew Apr 8 '10 at 14:43
add comment

7 Answers

up vote 3 down vote accepted

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:


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

share|improve this answer
I believe it is NFS but they don't let me near the servers. So what about multiple web apps in same server logging to the same file? That would be one process. –  Andrew Apr 7 '10 at 22:10
One process, many threads this is still the same. Also, aren't different web apps launched in separate processes? Anyway, this has a chance to work as at the beginning of my answer. But it is a bad idea to depend on that. –  pajton Apr 7 '10 at 22:15
All web apps of a server run in the same process. Ok, so it would be safe on the Unix level, but could still get interspersed logging. –  Andrew Apr 7 '10 at 22:20
Interspersed for sure and might work. It would be best to test it in your environment. If it works for a certain period of time it will probably work. –  pajton Apr 7 '10 at 22:22
add comment

In prudent mode logback will safely handle multiple JVMs possibly on different hosts writing to the same network-shared file. It can even deal with temporary network failures. Performance should be quite acceptable for few nodes, say 4 or less. For 5 or more nodes all logging heavily you may notice a performance hit.

share|improve this answer
add comment

We have a requirement where we need to produce a single file from all the managed server running the same application . we developed a java logging server which opens ups a port and listen for log event. we used the log4j socket appender to write log event to the same port and created a single file.

share|improve this answer
add comment

We use org.apache.log4j.net.SyslogAppender to log to a single machine using syslog, and it has worked well for us. I would recommend looking into that as an alternative.

share|improve this answer
Good suggestion. I imagine the calls are asynchronous so not much performance penalty –  Andrew Apr 7 '10 at 22:11
add comment

This looks like a really bad idea (corrupt logs, uncertainty of the source of a given log entry are two reasons that come to mind). If you are using Log4j in Weblogic like this, I suggest doing it by-the-book. This will allow you to use one file for the whole app server without any issues.

The suggestion of syncronizing the log writing makes no sense to me, as you would be basically blocking all applications in the app server when they write a log. If logging is frequent, that will slow everything down significantly.

As for multiple app servers, you need to use something other than file based logging if you want them all consolidated. There are a few ways to do this, one is to log to different files and have a different process combine them, but the better option is probably to use a network based logging repository, using Log4j's SocketAppender or some other method (nathan mentions SyslogAppender which is great if you want a Syslog) to ensure that the file access does not get corrupted.

share|improve this answer
add comment

Best case I would imagine you have a potential performance problem with sync access to the log file resource. Worst case would be some of the scenarios you mention.

I would ask two Qs: a) what was the desired goal with this config and b) can you find a better technical solution to achieve the goal.

My guess is that you have a sysadmin who wants to get a "single log file for the system." The file is thrown on the network share to make it easy to get to. The better answer for the goal might be multiple files, local to each system and something like http://www.splunk.com/ for a nice monitor.

share|improve this answer
add comment

If at all possible use a different file for each instance. This will give the best result with the least effort.

The logback alternative to log4j has a prudent mode to its log writer which explicitly jump through hoops to ensure that new things are written at the end of file. I don't think that will work on network shares then.

If you MUST have a central logging location, then consider setting up a server accepting log events and writing them to the appropriate files. This will ensure it is only a single process actually accessing the file system, and will let the JVM help all it can in terms of synchronization etc.

share|improve this answer
Logback's prudent mode works on network shares. For a few server nodes, say 4 or less, it will work quite nicely. –  Ceki Apr 8 '10 at 21:10
add comment

Your Answer


