Pregunta

I would like to configure log4j to write only files up to a maximum specified size, e.g. 5MB. When the log file hits 5MB I want it to start writing to a new file. I'd like to put some kind of meaningful timestamp into the logfile name to distinguish one file from the next.

I do not need it to rename or manipulate the old files in any way when a new one is written (compression would be a boon, but is not a must).

I absolutely do not want it to start deleting old files after a certain period of time or number of rolled files.

Timestamped chunks of N MB logfiles seems like the absolute basic minimum simple strategy I can imagine. It's so basic that I almost refuse to believe that it's not provided out of the box, yet I have been incapable of figuring out how to do this!

In particular, I have tried all incarnations of DailyRollingFileAppender, RollingFileAppender or the 'Extras' RollingFileAppender. All of these delete old files when the backupcount is exceeded. I don't want this, I want all my log files!

TimeBasedRollingPolicy from Extras does not fit because it doesn't have a max file size option and you cannot associate a secondary SizeBasedTriggeringPolicy (as it already implements TriggeringPolicy).

Is there an out of the box solution - preferably one that's in maven central?

¿Fue útil?

Solución

I gave up trying to get this to work out of the box. It turns out that uk.org.simonsite.log4j.appender.TimeAndSizeRollingAppender is, as the young folk apparently say, the bomb.

I tried getting in touch some time back to get the author to stick this into maven central, but no luck so far.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top