Problems with log4j dailyrollingfileappender file

We are facing a particular problem. Scenario: We have 3 servers that, with multiple instances of the component, write the transaction log to a single log file. We use log4j and servers running on Java 1.3. setAppend () is true, and implementation is DailyRollingFileAppender

Problem: At midnight, we expect the current log file to flip over with the new file name and start writing to the new file. This works well in our test setup (logs on a single server). In production, at midnight, a new file is created in which new records are recorded, but the minimized file is deleted.

Any help would be greatly appreciated, as it was after a couple of days, and we cannot get any conclusions for this problem.

+5
source share
3 answers

You do not have to register in one file from many processes. Log4j is thread safe, but it's not safe, so to speak; it does not work as a shared library between different java processes. Log4j, embedded in one Java application, is not aware of any other.

With rollover, it causes the problem that you just discovered: all processes run their own rollover code, blindly rewriting the previous contents (because none of them expect any).

A possible solution is here: Log4j Logging into a shared log file

+4
source

. , ( ). , : , .....

, , .

+2

, DailyRollingFileAppender ( , ​​..). , 31 -2014 , - sample.log. :

  • , (, 1:00 1 2015 ), .
  • . (.. sample-2014-12-31.log. , .).
  • . .. sample.log sample-2014-12-31.log.
  • . .. sample.log
  • sample.log.

, . :

  • WAR, , .
  • .
  • ..

, .

  • Windows, , .
  • On a Linux machine, the second process will delete the archive file created by the first process and rename the new file (currently used by the first process) to the file of the previous day. Thus, the first process will start writing the logs to the file of the previous day, the second process will write the logs to the new file. After midnight, the log file used by the first process will be deleted. Thus, the logs of the first process will be lost.
+1
source

All Articles