3

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")

Jim Raynor
  • 2,268
  • 3
  • 31
  • 36

2 Answers2

2

You could extend the FileAppender class or any other appender class and implement your custom version. Example
DailyRollingFileAppender

nayakam
  • 4,149
  • 7
  • 42
  • 62
  • Hi Thilakan! Do you know some custom DailyRollingFileAppender implementation with MaxFileSize property? Is that so can you please post that URL as above. Thanks a lot. – Channa Nov 21 '14 at 01:56
0

Have a look at the open-source TimeAndSizeRollingAppender in www.simonsite.org.uk, as stated in this answer at another question here at SO.

Community
  • 1
  • 1
espinchi
  • 9,144
  • 6
  • 58
  • 65