aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes log4j DailyRollingFileAppender question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "log4j DailyRollingFileAppender question" Watch "log4j DailyRollingFileAppender question" New topic
Author

log4j DailyRollingFileAppender question

Benjamin Hundley
Ranch Hand

Joined: Mar 06, 2006
Posts: 53
Does the DailyRolingFileAppender in log4j roll over if the program is not continuously running? I have a batch job written in Java that runs once a day and it is not continuously running. I am using log4j for logging. I have it configured to roll over each day and each new day that it runs it does not roll over to a new log file. It just appends to the old existing log file from the previous day. Does the program need to be continuously running for this feature to work?
m coffee
Greenhorn

Joined: Nov 10, 2010
Posts: 5
In our experience, once a rolling file appender is correctly configured, it creates a new file on each day change.

What is your configuration for the dailyrollingfileappender?
Vidyasagar Guntanala
Greenhorn

Joined: Dec 19, 2008
Posts: 2
I face the same issue as Benjamin. Here are my log4j.properties.

log4j.appender.details=org.apache.log4j.DailyRollingFileAppender
log4j.appender.details.File=log\\DOCLDT01_detail.log
log4j.appender.details.DatePattern='.'yyyy-MM-dd-HH
log4j.appender.details.layout=org.apache.log4j.PatternLayout
log4j.appender.details.layout.ConversionPattern=%-5p [%t] %-5p %M() - %m%n
log4j.appender.details.threshold=DEBUG
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Based on Benjamin's tests with programs which don't run continuously and my experience with programs which do run continuously, I'd have to say that the answers to his questions are:

Benjamin Hundley wrote:Does the DailyRolingFileAppender in log4j roll over if the program is not continuously running?


No.

Does the program need to be continuously running for this feature to work?


Yes.
Vidyasagar Guntanala
Greenhorn

Joined: Dec 19, 2008
Posts: 2
I found out why rollover is not working for me. The reason is, I am using multiple file appenders which write to same file. if we use multiple file appenders to write to a single file, log4j has issues with rollover for DailyRollingFileAppender.

And the program does not need to run continuously for log4 j to rollover. Rollover does not take place at the end of timeframe mentioned, instead, it takes place while writing first time to log after the timeframe.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: log4j DailyRollingFileAppender question