DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13099>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13099

DOMConfigurator ignores category factory setting





------- Additional Comments From [EMAIL PROTECTED]  2003-09-11 08:23 -------
I made some minor changes that helped at least in my case:
1. Make the org.apache.log4j.DefaultCategoryFactory and its
   constructor public (alternatively, implement your own CategoryFactory
   in the xml package).
2. Make the following changes to org.apache.log4j.xml.DOMConfigurator
new:
   // WK (26.08.2003): Replacement for the deprecated CATEGORY_FACTORY_TAG
  static final String LOGGER_FACTORY_TAG  = "loggerFactory";
new:
   /**
   * WK (26.08.2003): Method parameter list for retrieving a Logger using
   * a specific LoggerFactory as specified in the XML configuration
   */
  static final Class[] STRING_LOGFACTORY_PARAM = new Class[] {String.class,
LoggerFactory.class};
new:
   /**
   * WK (26.08.2003): LoggerFactory which is used when retrieving a Logger.
   * The LoggerFactory may be set using the CategoryFactory XML 
   */
  protected LoggerFactory loggerFactory = new DefaultCategoryFactory();
[changed in parseErrorHandler()]
            String loggerName = currentElement.getAttribute(REF_ATTR);
            // WK (26.08.2003): get the logger with the help of the loggerFactory
            Logger logger = repository.getLogger(loggerName, loggerFactory);
[changed]:
  protected
  void parseCategory (Element loggerElement) {
    // Create a new org.apache.log4j.Category object from the <category> element.
    String catName = subst(loggerElement.getAttribute(NAME_ATTR));

    Logger cat;    

    String className = subst(loggerElement.getAttribute(CLASS_ATTR));


    if(EMPTY_STR.equals(className)) {
      LogLog.debug("Retreiving an instance of org.apache.log4j.Logger.");
      // WK (26.08.2003): get the logger with the help of the loggerFactory
      cat = repository.getLogger(catName, loggerFactory);
    }
    else {
      LogLog.debug("Desired logger sub-class: ["+className+']');
       try {     
         // WK (26.08.2003): get the logger method by reflection which takes
         // a LoggerFactory as an argument
         Class clazz = Loader.loadClass(className);
         Method getInstanceMethod = clazz.getMethod("getLogger", 
                                                    STRING_LOGFACTORY_PARAM);
         cat = (Logger) getInstanceMethod.invoke(null, new Object[] {catName,
loggerFactory});
       } catch (Exception oops) {
         LogLog.error("Could not retrieve category ["+catName+
                      "]. Reported error follows.", oops);
         return;
       }
    }
[changed in parseCategoryFactory()]:
      // WK (26.08.2003): set the LoggerFactory to a user-defined one
      loggerFactory =
(LoggerFactory)OptionConverter.instantiateByClassName(className, 
                                                                
LoggerFactory.class, 
                                                                 null);
      PropertySetter propSetter = new PropertySetter(loggerFactory);
[changed in parse(Element)]:
        if (tagName.equals(CATEGORY_FACTORY_TAG) || 
tagName.equals(LOGGER_FACTORY_TAG)) {

3. Change the log4j.dtd
<!ELEMENT log4j:configuration (renderer*, appender*,(category|logger)*,root?,
                               (categoryFactory|loggerFactory)?)>
<!ELEMENT logger (param*,(priority|level)?,appender-ref*)>
<!ATTLIST logger
  class         CDATA   #IMPLIED
  name          ID      #REQUIRED
  additivity    (true|false) "true"  
>
4. New in log4j.dtd
<!-- WK (26.08.2003): as categories are deprecated a loggerFactory element -->
<!-- should be available as a replacement for the categoryFactory element -->
<!ELEMENT loggerFactory (param*)>
<!ATTLIST loggerFactory 
   class        CDATA #REQUIRED>

Hope this helps and might find its way in the next log4j release (following 1.2.8)

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

Reply via email to