0
votes

I'm using Log4j 2.3, rather than the latest 2.x version, because my code needs to run on Java 1.6. Anyway, I am configuring everything programmatically. When I create the RollingFileAppender with RollingFileAppender.createAppender, I pass in as the policy parameter:

SizeBasedTriggeringPolicy.createPolicy("10MB");

So far, so good. But I need to be able to change the max file size programattically at runtime. I could do it with log4j 1.2.x because my RollingFileAppender had a setMaxFileSize() method. But in 2.3, the triggerPolicy field of RollingFileAppender is read only, and the SizeBasedTriggeringPolicy that determines the max file size seems to be immutable. About the only thing I can see that might work is to remove the appender and replace it with a new one. Does anyone know a simpler solution?

1
Please check... Existing QuestionRuelos Joel
@fuzzy28 - that question was about log4j 1.2.x. Mine is about 2.x. 2.x was basically an incompatible ground-up rewrite. It's not the same question.Dave 114

1 Answers

0
votes

The answer is, in Log4j 2.3 you can't do what I'm trying to do. This was addressed in this bug fix:

Changes in SizeBasedTriggeringPolicy has no effects when automatic reconfiguration is on.

The fix will be released with log4j 2.5, which unfortunately for me, requires Java 1.7.