Log4j is a cool Java library which helps inserting log entry in the code. One of the best features of this logging library is the usage of the DailyRollingFileAppender for archive purposes. This appender allows you to roll the files with the user choosen frequency.
The configuration is quite simple, according to the manual:
# Default Log - Catch all
log4j.rootLogger=DEBUG, stdout, logfile
# Console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c.%M:%L] - <%m>%n
# File
log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logfile.File=${log.dir}/${log.apptype}/log.log
log4j.appender.logfile.DatePattern=.yyyy-MM-dd
As you can see, the log files are rolled with the layout defined by the DatePattern property: .yyyy-MM-dd. This should follow a valid SimpleDateFormat convention. However, in this way the old log files are stored like: log.log.2009-01-01, log.log.2009-01-02 and so on, which means a different extension every day! In order to solve this issue, it is possible to escape the literal with the quotes in the DatePattern property, and insert the extension in the pattern. This means that the DatePattern property can be like this:
log4j.appender.logfile.DatePattern='.'yyyy-MM-dd'.log'
By following this approach, each log file will be archived like log.log.2009-01-01.log, log.log.2009-01-02.log.