2

Kindly let me know if there is a way to rotate the logfiles based on time as well as size.

The log file is required to be in a format logfilename.log.date when the roll over happens based on time.

MrSmith42
  • 9,961
  • 6
  • 38
  • 49

2 Answers2

2

If you want to do the rotation based on time DailyRollingFileAppender probably is the best practice. You can have yearly, monthly, hourly etc logs based on your configuration.

If you want size based rotation RollingFileAppender could be very useful.

Furthermore, if you want to use both time and size at the same time I would suggest you to take a look at TimeAndSizeRollingAppender, free under the Apache 2.0 license, which claims to be providing full features of both DailyRollingFileAppender and RollingFileAppender.

Korhan Ozturk
  • 11,148
  • 6
  • 36
  • 49
0

Take a look at DailyRollingFileAppender and RollingFileAppender.

http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/DailyRollingFileAppender.html

http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/RollingFileAppender.html

Jerry B
  • 135
  • 1
  • 9
  • Can anyone kindly let me know how to use the features of RollingFile Appender(rotate based on size) and dailyrollingfileappender(to rotate base on time) in the same configuration. Tried following http://www.mailinglistarchive.com/html/log4j-user@logging.apache.org/2008-07/msg00355.html, but the rotation based on size is not happening.Tried setting the size to 3KB. – akshatha shetty Feb 14 '13 at 05:58