one quick thought - the Log4j team specifically recommends against
subclassing logger.
If you need to "wrap" log4j for any reason use the Decorator (or "Wrapper")
design pattern.

In the long manual Ceki states that sub-classing logger is "inherently
unsafe".  I ran into this problem myself and refactored as he recommends.
Since then we've had no problems, and I can sleep at night. zzzz

Mike

-----Original Message-----
From: Sikha, Naresh [mailto:[EMAIL PROTECTED]
Sent: Tuesday, April 20, 2004 5:57 PM
To: 'Log4J Users List'
Subject: RE: ClassCast exception for factory


If all you are looking for is a configuration safe Hierarchy, then try:

private Logger logger = ConversionLoggerFactory.getLogger(getClass());

Where:

import org.apache.log4j.Hierarchy;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.helpers.Constants;
import org.apache.log4j.helpers.Loader;
import org.apache.log4j.spi.RootCategory;

public class ConversionLoggerFactory {
        
        private static final ConversionLoggerFactory c_instance = new
ConversionLoggerFactory();
        
        public static Logger getLogger(final Class c) {
                return c_instance.m_hierarchy.getLogger(c.getName());
        }
        
        private final Hierarchy m_hierarchy;
        
        private ConversionLoggerFactory() {
                m_hierarchy = new Hierarchy(new RootCategory(Level.DEBUG));
                new
PropertyConfigurator().doConfigure(Loader.getResource(Constants.DEFAULT_CONF
IGURATION_FILE), m_hierarchy);
        }
}


There's no need to wrap/subclass logger, just specify where you would like
to find configuration safe instances of it.

Cheers.

Naresh Sikha 



-----Original Message-----
From: Peake, Chris [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, April 20, 2004 1:36 PM
To: [EMAIL PROTECTED]
Subject: ClassCast exception for factory


I am trying to implement a new logger factory to get around a problem I
posted earlier. I am failing with a classcast exception on the statment
below:
 
    private  ConversionLogger logger = (ConversionLogger)
ConversionLogger.getInstance(this.getClass());
 
The ConverstionLogger and ConversionLoogerFactory are based exactly on the
excamples in source.
 
After trying to figure out how to specify the factory in the properties
file, I came across an answer like below:
log4j.categoryFactory=com.ca.cleverpath.portal.migrate.importer.Conversi
onLoggerFactory.class
 
But I still get the classcast.
 
Can someone help on this?
 
thanks



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

-------------------------------------------------------------------------------
This message and any included attachments are from Siemens Medical Solutions 
USA, Inc. and are intended only for the addressee(s).  
The information contained herein may include trade secrets or privileged or 
otherwise confidential information.  Unauthorized review, forwarding, printing, 
copying, distributing, or using such information is strictly prohibited and may 
be unlawful.  If you received this message in error, or have reason to believe 
you are not authorized to receive it, please promptly delete this message and 
notify the sender by e-mail with a copy to [EMAIL PROTECTED] 

Thank you

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

Reply via email to