For reasons I won’t get into I’m forced to configure a log4j appender programmatically.
I want to use a RollingFileAppender so I can control the maximum number of files that are kept around.
Also I want to set this appender to use a TimeBasedRollingPolicy as that will automatically take care of compressing the rolled files.
Problem is I can’t see a way to set this through code. When setting up a RollingFileAppender normally through a properties file you would have:
log4j.appender.LOGFILE.RollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy
There must be a way of setting this …. ? Can anyone shed some light, digging through the javadoc and the basic eclipse-reflection of the classes methods hasn’t revealed the solution 🙁
You might need the log4j companions/extras to use the rolling.RollingFileAppender.
http://logging.apache.org/log4j/companions/index.html
EDIT:
Here is the api reference that lets you set the rolling policy.
http://logging.apache.org/log4j/companions/apidocs/org/apache/log4j/rolling/RollingFileAppender.html