• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

log4j DailyRollingFileAppender question

 
Benjamin Hundley
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic