You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Paul Smith <Pa...@lawlex.com.au> on 2003/07/03 23:55:09 UTC

RE: DailyRollingFileAppender - why isn't rollOver protected

> Thanks.
> 
> I already told Ceki my opinion about log4j (I think it is 
> really great and I
> love it).  I would gladly check the file in jakarta-log4j and 
> tell you if it
> solves my problem or any other feedback I have.  However, I 
> have to admit
> that I don't know how to find it.
> I never browsed the CVS before, the best I could find is:
> http://cvs.apache.org/viewcvs.cgi/jakarta-log4j/src/java/org/a
> pache/log4j/Da
> ilyRollingFileAppender.java
> but this claimed to be version 1.24 and suffer from all the 
> problems I have
> in version 1.28.
> 
> can you help me finding the right file.

Hello Avner, 

Firstly apologise for the lengthy days  delay in responding, I have been off
work due to the dreaded flu that is hitting everyone here in Australia.

Your question gave me an opportunity to explore more Ceki's new rollover
area so that I can respond with at least some facts.

>From what I can tell by browsing the code, the relevant packages in the
jakarta-log4j are org.apache.log4j.rolling and it's 'helper' sub-package. 

http://cvs.apache.org/viewcvs.cgi/jakarta-log4j/src/java/org/apache/log4j/ro
lling/

Inside this main package is a brand new RollingFileAppender class, which you
can use, and configure it with an implementation of a TriggeringPolicy, and
a RollingPolicy. (This is the classic strategy pattern to allow you to
plugin different ways of doing things).  There will now be no need to
sub-class the RollingAppender class, but just provide the RollingAppender
with a custom TriggerPolicy or RollingPolicy as is required in your
circumstances.

A TriggeringPolicy is the 'when' of how the appender should roll, and the
RollingPolicy is the 'how' the rolling actually occurs.  You will notice
that the rolling package has a TimeBasedRollingPolicy, and a
SizedBasedTriggerPolicy class, these implement the classic configs of
yester-year by Rolling based on time or by size.

In your case you could probably choose to wrap one of these existing
policies in your own class, first checking if anyone is reading the file,
and if it meets at least those requirements, forwarding on the call to the
wrapped Policy to do the work.  Wrapping is usually my preferred way of
doing things, but you may just prefer to sub-class, either works fine.

I hope this helps you.

regards,

Paul Smith

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org