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 Geert Mergan <gm...@europeaninvestor.com> on 2001/02/15 16:42:10 UTC

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: gme@europeaninvestor.com
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


Re: adding custom priorities

Posted by Ceki Gülcü <cg...@qos.ch>.
At 16:42 15.02.2001 +0100, you wrote:
>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).

Good point, I have made the XYZ_INT fields in Priority.java public as they are final anyway.

>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...

No, it is easier than you think. First, I suggest that you check out the latest version of log4j as it is cleaner in many respects. I believe to be production ready as well. 

Once you have the CVS version, see the examples in ...org/apache/log4j/xml/exaples/XCategory.java and other files in the same directory. By the way, you do not need to sub-class Hierarchy class. There is also documentation by Paul Glezen explaining how to extend log4j. Cheers, Ceki


----
Ceki Gülcü           e-mail: cgu@qos.ch (preferred)
av. de Rumine 5              ceki_gulcu@yahoo.com
CH-1005 Lausanne          
Switzerland            Tel: ++41 21 351 23 15