Reputation: 2268
I know that log4j provides RollingFileAppender and DailyRollingFileAppender classes, however, DailyRollingFileAppender does not support MaxFileSize property.
How do I tweak the behavior of log4j so that it can log in a way like this: the rolling policy is based on both time period (and file name is appended with DatePattern), like in DailyRollingFileAppender, and MaxFileSize (like in RollingFileAppender)?
Example:
The log file rolls every hours (file name will be appended time stamp such as YYYY-MM-DD_HH-MM-SS (normally MM and SS will be "00" and "00")
The maxFileSize is limited to 1MB
During the two checkpoints of the roll over cycle every hour, if an event of exceeding maxFileSize occurs, the log file should roll over as well, (which means the minute and second stamp will take some value different than "00")
Upvotes: 3
Views: 6745
Reputation: 9212
Have a look at the open-source TimeAndSizeRollingAppender in www.simonsite.org.uk, as stated in this answer at another question here at SO.
Upvotes: 0
Reputation: 4239
You could extend the FileAppender class or any other appender class and implement your custom version. Example
DailyRollingFileAppender
Upvotes: 2