Discussion:
programmatically change max file size of RollingFileAppender
Dave Glasser
2015-12-09 04:56:04 UTC
Permalink
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?
Ralph Goers
2015-12-09 06:25:00 UTC
Permalink
This was fixed in LOG4J2-381. Unfortunately that is in the 2.5 release so would require Java 7. I suppose you could back port the fix to 2.3.

Ralph
Post by Dave Glasser
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?
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-***@logging.apache.org
For additional commands, e-mail: log4j-user-***@logging.apache.org
Dave Glasser
2015-12-09 11:56:48 UTC
Permalink
                                                                                                                                                                 
Thanks Ralph. I'll either have to apply that patch or go back to 1.2.x, because the software already has that functionality using 1.2.x, and it can't be taken out.
I notice that with the patch the size is updated through the RollingFileManager, but I can't figure out a way to get a reference to that. Any help on that one?
From: Ralph Goers <***@dslextreme.com>
To: Log4J Users List <log4j-***@logging.apache.org>; Dave Glasser <***@pobox.com>
Sent: Wednesday, December 9, 2015 1:25 AM
Subject: Re: programmatically change max file size of RollingFileAppender

This was fixed in LOG4J2-381. Unfortunately that is in the 2.5 release so would require Java 7.  I suppose you could back port the fix to 2.3.

Ralph
Post by Dave Glasser
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?
Ralph Goers
2015-12-09 12:28:18 UTC
Permalink
I will look into it. Fwiw, if you fork 2.3 and apply the patch it is possible we could go ahead and do a 2.3.1 release. If there is other stuff you would want included you could also do that on your fork.

Ralph
Post by Dave Glasser
Thanks Ralph. I'll either have to apply that patch or go back to 1.2.x, because the software already has that functionality using 1.2.x, and it can't be taken out.
I notice that with the patch the size is updated through the RollingFileManager, but I can't figure out a way to get a reference to that. Any help on that one?
Sent: Wednesday, December 9, 2015 1:25 AM
Subject: Re: programmatically change max file size of RollingFileAppender
This was fixed in LOG4J2-381. Unfortunately that is in the 2.5 release so would require Java 7. I suppose you could back port the fix to 2.3.
Ralph
Post by Dave Glasser
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?
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-***@logging.apache.org
For additional commands, e-mail: log4j-user-***@logging.apache.org
Loading...