You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Pearce, Lyall" <ly...@eds.com> on 2006/04/18 05:45:50 UTC

1.3-alpha8 - Extending TimeBasedRollingPolicy

I am unsure if this is more a user or developer question, I will lean
towards developer unless told otherwise.


log4j1.3-alpha8 has a nice class TimeBasedRollingPolicy
(http://logging.apache.org/log4j/docs/api-1.3/org/apache/log4j/rolling/T
imeBasedRollingPolicy.html)

The Primary question: Why are the classes marked final? Why can't I
extend a log4j class?

An additional question/observation: The javadoc says we can decouple the
active log file using setActiveFileName - which is really nice from my
perspective, but the method is deprecated with no obvious alternative.


The Background.

I wanted to extend this to not only roll the file but to transmit the
file, via http (or any protocol, I suppose) to another server, after
all, TimeBasedRollingPolicy seemed to do everything I wanted in so far
as rolling the file is concerned, I just wanted to do a teeny bit more
with the file (if you consider transferring the log file elsewhere a
teeny bit)

I admit to being new to log4j and java in general (but not to computing)
but these log4j classes are marked final, so I cannot 'extend' them.

Also, the documentation is a little thin, from my perspective, with how
I could go about doing a 'TimeBasedRollingAndTransferPolicy' class given
the whole log4j framework?

For example, RollingPolicy.RolloverDescription() says '...performs any
necessary preliminary actions and describes actions needed after close
of current log file...'
(http://logging.apache.org/log4j/docs/api-1.3/org/apache/log4j/rolling/R
ollingPolicy.html) - what is it describing, how?

Thanks in advance.

...Lyall

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


Re: 1.3-alpha8 - Extending TimeBasedRollingPolicy

Posted by Curt Arnold <ca...@apache.org>.
On Apr 20, 2006, at 3:05 PM, Boris Unckel wrote:

> Hello Lyall,
>
> Pearce, Lyall wrote:
>> I am unsure if this is more a user or developer question, I will lean
>> towards developer unless told otherwise.
>>
>>
>> log4j1.3-alpha8 has a nice class TimeBasedRollingPolicy
>> (http://logging.apache.org/log4j/docs/api-1.3/org/apache/log4j/ 
>> rolling/T
>> imeBasedRollingPolicy.html)
>>
>> The Primary question: Why are the classes marked final? Why can't I
>> extend a log4j class?
> I am not a log4j developer. I have seen the discussions about  
> compatibility on this list for the development of log4j 1.3
> and the enormous efforts spend on compatibility.
> It is very hard to change the internal implementation of an class  
> if lots of people are extending it and relying on a specific
> behaviour.
> If you want to have your homegrown XYZPolicy: Copy the code,  
> implement the interface and use it.
> If log4j developers want to change something, they just have to  
> care that the interface is not broken, but they can
> change the other class without braking anyones code.
>
> Regards
> Boris
>

That is the reason that new stuff is generally marked final.  For a  
more complete discussion see "Item 15: Design or document for  
inheritance or prohibit it" in "Effective Java".

If there is a compelling reason that something should be open for  
extension, then it is always possible to drop the final qualifier,  
however it is impossible to put final on a class without  
compatibility issues.  The default behavior now is to tightly  
constrain new code and loosen it up if and when compelling use cases  
are presented.

Instead of copying code, your implementation of the interface could  
delegate to an instance of TimeBasedRollingPolicy.  For a discussion  
on that, see "Item 14: Favor composition over inheritance".



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


Re: 1.3-alpha8 - Extending TimeBasedRollingPolicy

Posted by Boris Unckel <bo...@gmx.net>.
Hello Lyall,

Pearce, Lyall wrote:
> I am unsure if this is more a user or developer question, I will lean
> towards developer unless told otherwise.
>
>
> log4j1.3-alpha8 has a nice class TimeBasedRollingPolicy
> (http://logging.apache.org/log4j/docs/api-1.3/org/apache/log4j/rolling/T
> imeBasedRollingPolicy.html)
>
> The Primary question: Why are the classes marked final? Why can't I
> extend a log4j class?
I am not a log4j developer. I have seen the discussions about 
compatibility on this list for the development of log4j 1.3
and the enormous efforts spend on compatibility.
It is very hard to change the internal implementation of an class if 
lots of people are extending it and relying on a specific
behaviour.
If you want to have your homegrown XYZPolicy: Copy the code, implement 
the interface and use it.
If log4j developers want to change something, they just have to care 
that the interface is not broken, but they can
change the other class without braking anyones code.

Regards
Boris


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