logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sanjay Gupta \(sanjaygu\)" <sanja...@cisco.com>
Subject Extending PatternLayout- Is it possible in log4j-1.2.8?
Date Tue, 15 Jul 2003 00:43:53 GMT

I am trying to add few conversion characters to pattern layout. Values
of some of them are known at the logger initialization and for few it
can be passed per-message. I was looking at following guideline -


This seems to fit my needs perfectly. Then I realized that we should use
Logger instead of Category class. Java doc also says that Category is
deprecated. Fine, Now when I try to subclass Logger, it is not possible
as well as not advisable for various reasons. See the conversation
thread below. So, now I have a road block. I can not use Category class.
I can not sublcass Logger. If I wrap Logger class, I can not override
forcedLog method of Logger/Category so as to provide my custom
LoggingEvent class. 
Please help me to figure out how to do this. I think the guideline in
above URL is not possible with log4j-1.2.8. What I am wondering is
whether it is possible to add conversion charactors to PatternLayout? 


-----Original Message-----
From: Ceki Gülcü [mailto:ceki@qos.ch] 
Sent: Monday, July 14, 2003 1:44 PM
To: Log4J Users List
Subject: Re: A possible BUG? Logger vs category tag in xml

This subject has been discussed many times in the past. Please refer to
the archives.

No, it is not a bug. Subclassing logger class is discouraged.
Consequently, the logger tag does not allow for a class attribute.
However, you can get around this by various means which I am not going
to disclose here as the means are deprecated, discouraged or both.

I recommend wrapping instead of sub-classing.

At 12:21 PM 7/14/2003 -0700, Sanjay Gupta (sanjaygu) wrote:

>I am trying to subclass Logger(Category) & LoggerFactory and use 
>DOMConfigurator(log4j.xml). I ran into interesting problem. My stuff 
>works fine when I configure the logger from program i.e. not using a 
>xml or properties file. But when I use xml file, it turns out that 
><logger> tag does not have a way of specifying class so My subclassed 
>Logger never gets instanciated. I digged deeper and figured out that 
><category> tag has "class" attribute.
>So, now I am confused. Should I subclass Logger or Category. If I
>subclass Logger then how can I make sure that my subclassed Logger gets
>instanciated from the log4j.xml and not org.apache.log4j.Logger?
>I think that it might be a bug?

Ceki  For log4j documentation consider "The complete log4j manual"
       ISBN: 2970036908  http://www.qos.ch/shop/products/clm_t.jsp 

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

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

View raw message