Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j dailyrollingfileappender file issues

Tags:

java

log4j

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 log4j and the servers run in Java 1.3. setAppend() is passed true and implementation is DailyRollingFileAppender

Problem: At midnight, we are expecting the current log file to roll over with a new file name and start writing to a new file. This is working well in our test setup (single server writing logs). In production, at midnight, new file is getting created where new logs are getting written but rolled over file is getting deleted

Any help will be highly appreciated as its been couple of days and we are not able to get any leads for the problem.

like image 741
rajesh Avatar asked Sep 21 '11 13:09

rajesh


People also ask

What is DailyRollingFileAppender?

DailyRollingFileAppender extends FileAppender so that the underlying file is rolled over at a user chosen frequency.

How do you create a new log file for each time the application runs log4j?

File with system properties name and some prefix text if you want. This will create a log file with current date time, something like this Log4jDemoApp-dd-MM-yyyy-hh-mm-ss. log every time we run the application. It will create the new file because for every run we are setting current date stamp in system properties.

What is rolling file Appender in Log4j2?

Log4j2 RollingFileAppender is an OutputStreamAppender that writes log messages to files, following a configured triggering policy about when a rollover (backup) should occur. It also has a configured rollover strategy about how to rollover the file.


1 Answers

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

like image 82
MaDa Avatar answered Nov 02 '22 11:11

MaDa