Hi Geert,

This all sounds very familiar - been there!

An alternative approach to creating a new Category class,
and all the related gumph is to create a *wrapper* for
Category that knows about the custom priorities.

Advantages:
(a) no casting
(b) no need for custom CategoryFactory, etc.
(c) most of your code can refer to the wrapper object
    using your own package names instead of org.apache.log4j,
    which makes things more portable.

Disadvantages:
* a few extra wrapper objects
* very slight overhead

Attached is my wrapper class: hope it helps.

Regards,

Simon

 <<log.java>> 

Note that the code refers to a class called "Priority". This is actually
a custom priority class in the same package, *not*
org.apache.log4j.Priority.
In fact, here it is..
 <<Priority.java>> 


> -----Original Message-----
> From: Geert Mergan [SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, February 15, 2001 4:42 PM
> To:   [EMAIL PROTECTED]
> Subject:      adding custom priorities
> 
> Hello,
> 
> I suppose I'm not the only one's trying to define custom priorities
> (TRACE,
> ALWAYS, DEBUG2). It seems this is not as easy as I hoped it would be.
> 
> I've started with writing MyPriority (extending Priority as the javadoc
> says
> you shoulds when enlarging the priority set). That already gave some
> problems because the _INT fields have package scope. This seems like a
> design flaw to me, since I'd like to access these fields in MyPriority (in
> com.mycompany.util.logging package), but I managed to bypass via
> copy/paste
> (or so I hope).
> 
> Now the next thing I do is writing MyCategory (extends Category) since I
> need to add the methods trace(), always() and debug2(). I suppose I must
> also implement getInstance() because otherwise I won't be able to create
> MyCategory events. And then I have to write a MyHierarchy class since
> getInstance() requires a hierarchy and who knows what other classes I'll
> have to subclass and I won't even be sure that it will work so...
> 
> I start to suspect I'm not on the right track to add custom priorities.
> Anyone every tried to add custom priorities?
> 
> G.
> ---------------
> Geert Mergan
> Java Developer
> Email: [EMAIL PROTECTED]
> Phone: +32-2-3571765
> 
> EuropeanInvestor.com
> Lasne Business Park
> Chaussée de Louvain 431, Building F
> B-1380 Lasne
> Phone: +32-2-3571711
> Fax: +32-2-3571700
> URL: http://www.europeaninvestor.com
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

log.java

Priority.java

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to