We are encountering a peculiar problem. Scenario: We have 3 servers which with multiple instances of a component all writing transactional log to a single log file.We use lo
Say you have configured DailyRollingFileAppender with daily rotation (It can be configured for rotation every hour, minute etc). Say, it is 31-Dec-2014 today and log file name is sample.log. Log rotation will happen in the following way:
If two instances of Log Manager points to same log file then each instance will independently repeats above steps on the same file. This can happen in any of the following scenarios:
Such scenario leads to the issue mentioned in the question.
We ran into the same problem. The underlying problem is that there is no way to coordinate access to log file across multiple processes (in this case running on multiple servers.) This means all sorts of bad things happen: logs gets overwritten, files fail to roll etc...
My suggestion to you is to have each server write to a separate file, and then merge them in a post processing job.
You should not log to the same file from many processes. Log4j is thread-safe all right, but it's not process-safe, if I may say so; it does not work as a shared library among different java processes. Log4j embedded in one java application has no knowledge of any other one.
With rollover it causes the problem you've just discovered: all processes run their own rollover code, blindly overwriting the previous contents (because none of them expects any).
A possible solution here: Log4j Logging to a Shared Log File