You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ca...@apache.org on 2007/03/23 22:05:15 UTC
svn commit: r521903 - in /logging/log4j/branches/v1_2-branch: docs/
src/java/org/apache/log4j/xml/ src/xdocs/ tests/input/xml/
tests/src/java/org/apache/log4j/xml/
Author: carnold
Date: Fri Mar 23 14:05:14 2007
New Revision: 521903
URL: http://svn.apache.org/viewvc?view=rev&rev=521903
Log:
Bug 33708: XMLConfiguration of loggerFactory does not work
Added:
logging/log4j/branches/v1_2-branch/tests/input/xml/categoryfactory1.xml
logging/log4j/branches/v1_2-branch/tests/input/xml/categoryfactory2.xml
logging/log4j/branches/v1_2-branch/tests/input/xml/loggerfactory1.xml
Modified:
logging/log4j/branches/v1_2-branch/docs/HISTORY.txt
logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/xml/DOMConfigurator.java
logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/xml/log4j.dtd
logging/log4j/branches/v1_2-branch/src/xdocs/download.xml
logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/xml/DOMTestCase.java
Modified: logging/log4j/branches/v1_2-branch/docs/HISTORY.txt
URL: http://svn.apache.org/viewvc/logging/log4j/branches/v1_2-branch/docs/HISTORY.txt?view=diff&rev=521903&r1=521902&r2=521903
==============================================================================
--- logging/log4j/branches/v1_2-branch/docs/HISTORY.txt (original)
+++ logging/log4j/branches/v1_2-branch/docs/HISTORY.txt Fri Mar 23 14:05:14 2007
@@ -5,7 +5,7 @@
client code.
[***] Changes requiring important modifications to existing client code.
- March 5th, 2007
+ TBD, 2007
- Release of version 1.2.15
@@ -39,6 +39,7 @@
37864: Add target to generate binary and source compatibility report
41708: PropertyPrinter.printOptions breaking signature change in log4j 1.2.9
41735: RollingFileAppender may delete files during rollover
+ 33708: XMLConfiguration of loggerFactory does not work
September 18th, 2006
Modified: logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/xml/DOMConfigurator.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/xml/DOMConfigurator.java?view=diff&rev=521903&r1=521902&r2=521903
==============================================================================
--- logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/xml/DOMConfigurator.java (original)
+++ logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/xml/DOMConfigurator.java Fri Mar 23 14:05:14 2007
@@ -80,6 +80,7 @@
static final String LOGGER = "logger";
static final String LOGGER_REF = "logger-ref";
static final String CATEGORY_FACTORY_TAG = "categoryFactory";
+ static final String LOGGER_FACTORY_TAG = "loggerFactory";
static final String NAME_ATTR = "name";
static final String CLASS_ATTR = "class";
static final String VALUE_ATTR = "value";
@@ -109,6 +110,8 @@
Properties props;
LoggerRepository repository;
+ protected LoggerFactory catFactory = null;
+
/**
No argument constructor.
*/
@@ -258,7 +261,8 @@
eh.setBackupAppender(findAppenderByReference(currentElement));
} else if(tagName.equals(LOGGER_REF)) {
String loggerName = currentElement.getAttribute(REF_ATTR);
- Logger logger = repository.getLogger(loggerName);
+ Logger logger = (catFactory == null) ? repository.getLogger(loggerName)
+ : repository.getLogger(loggerName, catFactory);
eh.setLogger(logger);
} else if(tagName.equals(ROOT_REF)) {
Logger root = repository.getRootLogger();
@@ -317,7 +321,7 @@
if(EMPTY_STR.equals(className)) {
LogLog.debug("Retreiving an instance of org.apache.log4j.Logger.");
- cat = repository.getLogger(catName);
+ cat = (catFactory == null) ? repository.getLogger(catName) : repository.getLogger(catName, catFactory);
}
else {
LogLog.debug("Desired logger sub-class: ["+className+']');
@@ -361,10 +365,15 @@
}
else {
LogLog.debug("Desired category factory: ["+className+']');
- Object catFactory = OptionConverter.instantiateByClassName(className,
+ Object factory = OptionConverter.instantiateByClassName(className,
LoggerFactory.class,
null);
- PropertySetter propSetter = new PropertySetter(catFactory);
+ if (factory instanceof LoggerFactory) {
+ catFactory = (LoggerFactory) factory;
+ } else {
+ LogLog.error("Category Factory class " + className + " does not implement org.apache.log4j.LoggerFactory");
+ }
+ PropertySetter propSetter = new PropertySetter(factory);
Element currentElement = null;
Node currentNode = null;
@@ -812,7 +821,7 @@
currentElement = (Element) currentNode;
tagName = currentElement.getTagName();
- if (tagName.equals(CATEGORY_FACTORY_TAG)) {
+ if (tagName.equals(CATEGORY_FACTORY_TAG) || tagName.equals(LOGGER_FACTORY_TAG)) {
parseCategoryFactory(currentElement);
}
}
Modified: logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/xml/log4j.dtd
URL: http://svn.apache.org/viewvc/logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/xml/log4j.dtd?view=diff&rev=521903&r1=521902&r2=521903
==============================================================================
--- logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/xml/log4j.dtd (original)
+++ logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/xml/log4j.dtd Fri Mar 23 14:05:14 2007
@@ -9,7 +9,7 @@
element. -->
<!ELEMENT log4j:configuration (renderer*, appender*,(category|logger)*,root?,
- categoryFactory?)>
+ (categoryFactory|loggerFactory)?)>
<!-- The "threshold" attribute takes a level value such that all -->
<!-- logging statements with a level equal or below this value are -->
@@ -116,6 +116,10 @@
<!ELEMENT categoryFactory (param*)>
<!ATTLIST categoryFactory
+ class CDATA #REQUIRED>
+
+<!ELEMENT loggerFactory (param*)>
+<!ATTLIST loggerFactory
class CDATA #REQUIRED>
<!ELEMENT appender-ref EMPTY>
Modified: logging/log4j/branches/v1_2-branch/src/xdocs/download.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/v1_2-branch/src/xdocs/download.xml?view=diff&rev=521903&r1=521902&r2=521903
==============================================================================
--- logging/log4j/branches/v1_2-branch/src/xdocs/download.xml (original)
+++ logging/log4j/branches/v1_2-branch/src/xdocs/download.xml Fri Mar 23 14:05:14 2007
@@ -64,6 +64,7 @@
<li><a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=37864">37864</a>: Add target to generate binary and source compatibility report</li>
<li><a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=41708">41708</a>: PropertyPrinter.printOptions breaking signature change in log4j 1.2.9</li>
<li><a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=41735">41735</a>: RollingFileAppender may delete files during rollover</li>
+ <li><a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=33708">33708</a>: XML configuration of loggerFactory does not work</li>
</ul>
</li>
</ul>
Added: logging/log4j/branches/v1_2-branch/tests/input/xml/categoryfactory1.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/v1_2-branch/tests/input/xml/categoryfactory1.xml?view=auto&rev=521903
==============================================================================
--- logging/log4j/branches/v1_2-branch/tests/input/xml/categoryfactory1.xml (added)
+++ logging/log4j/branches/v1_2-branch/tests/input/xml/categoryfactory1.xml Fri Mar 23 14:05:14 2007
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
+
+ <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%m%n"/>
+ </layout>
+ </appender>
+
+ <logger name="org.apache.log4j.xml.DOMTestCase.testCategoryFactory1.1">
+ <appender-ref ref="CONSOLE" />
+ </logger>
+
+ <categoryFactory class="org.apache.log4j.xml.DOMTestCase$CustomLoggerFactory">
+ <param name="additivity" value="false"/>
+ </categoryFactory>
+
+</log4j:configuration>
\ No newline at end of file
Added: logging/log4j/branches/v1_2-branch/tests/input/xml/categoryfactory2.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/v1_2-branch/tests/input/xml/categoryfactory2.xml?view=auto&rev=521903
==============================================================================
--- logging/log4j/branches/v1_2-branch/tests/input/xml/categoryfactory2.xml (added)
+++ logging/log4j/branches/v1_2-branch/tests/input/xml/categoryfactory2.xml Fri Mar 23 14:05:14 2007
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
+
+ <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <errorHandler class="org.apache.log4j.xml.DOMTestCase$CustomErrorHandler">
+ <logger-ref ref="org.apache.log4j.xml.DOMTestCase.testCategoryFactory2.1"/>
+ </errorHandler>
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%m%n"/>
+ </layout>
+ </appender>
+
+ <root>
+ <appender-ref ref="CONSOLE" />
+ </root>
+
+ <categoryFactory class="org.apache.log4j.xml.DOMTestCase$CustomLoggerFactory">
+ <param name="additivity" value="false"/>
+ </categoryFactory>
+
+</log4j:configuration>
\ No newline at end of file
Added: logging/log4j/branches/v1_2-branch/tests/input/xml/loggerfactory1.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/v1_2-branch/tests/input/xml/loggerfactory1.xml?view=auto&rev=521903
==============================================================================
--- logging/log4j/branches/v1_2-branch/tests/input/xml/loggerfactory1.xml (added)
+++ logging/log4j/branches/v1_2-branch/tests/input/xml/loggerfactory1.xml Fri Mar 23 14:05:14 2007
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
+
+ <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%m%n"/>
+ </layout>
+ </appender>
+
+ <logger name="org.apache.log4j.xml.DOMTestCase.testLoggerFactory1.1">
+ <appender-ref ref="CONSOLE" />
+ </logger>
+
+ <loggerFactory class="org.apache.log4j.xml.DOMTestCase$CustomLoggerFactory">
+ <param name="additivity" value="false"/>
+ </loggerFactory>
+
+</log4j:configuration>
\ No newline at end of file
Modified: logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/xml/DOMTestCase.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/xml/DOMTestCase.java?view=diff&rev=521903&r1=521902&r2=521903
==============================================================================
--- logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/xml/DOMTestCase.java (original)
+++ logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/xml/DOMTestCase.java Fri Mar 23 14:05:14 2007
@@ -18,19 +18,20 @@
package org.apache.log4j.xml;
import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import junit.framework.Test;
-
-import org.apache.log4j.Logger;
+import org.apache.log4j.Appender;
import org.apache.log4j.Level;
-import org.apache.log4j.util.Filter;
-import org.apache.log4j.util.LineNumberFilter;
+import org.apache.log4j.Logger;
+import org.apache.log4j.spi.ErrorHandler;
+import org.apache.log4j.spi.LoggerFactory;
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.util.Compare;
import org.apache.log4j.util.ControlFilter;
+import org.apache.log4j.util.Filter;
import org.apache.log4j.util.ISO8601Filter;
-import org.apache.log4j.util.Transformer;
-import org.apache.log4j.util.Compare;
-import org.apache.log4j.util.SunReflectFilter;
import org.apache.log4j.util.JunitTestRunnerFilter;
+import org.apache.log4j.util.LineNumberFilter;
+import org.apache.log4j.util.SunReflectFilter;
+import org.apache.log4j.util.Transformer;
public class DOMTestCase extends TestCase {
@@ -159,4 +160,123 @@
root.error("Message " + i, e);
}
+
+
+ /**
+ * CustomLogger implementation for testCategoryFactory1 and 2.
+ */
+ private static class CustomLogger extends Logger {
+ /**
+ * Creates new instance.
+ * @param name logger name.
+ */
+ public CustomLogger(final String name) {
+ super(name);
+ }
+ }
+
+ /**
+ * Creates new instances of CustomLogger.
+ */
+ public static class CustomLoggerFactory implements LoggerFactory {
+ /**
+ * Addivity, expected to be set false in configuration file.
+ */
+ private boolean additivity;
+
+ /**
+ * Create new instance of factory.
+ */
+ public CustomLoggerFactory() {
+ additivity = true;
+ }
+
+ /**
+ * Create new logger.
+ * @param name logger name.
+ * @return new logger.
+ */
+ public Logger makeNewLoggerInstance(final String name) {
+ Logger logger = new CustomLogger(name);
+ assertFalse(additivity);
+ return logger;
+ }
+
+ /**
+ * Set additivity.
+ * @param newVal new value of additivity.
+ */
+ public void setAdditivity(final boolean newVal) {
+ additivity = newVal;
+ }
+ }
+
+ /**
+ * CustomErrorHandler for testCategoryFactory2.
+ */
+ public static class CustomErrorHandler implements ErrorHandler {
+ public CustomErrorHandler() {}
+ public void activateOptions() {}
+ public void setLogger(final Logger logger) {}
+ public void error(String message, Exception e, int errorCode) {}
+ public void error(String message) {}
+ public void error(String message, Exception e, int errorCode, LoggingEvent event) {}
+ public void setAppender(Appender appender) {}
+ public void setBackupAppender(Appender appender) {}
+ }
+
+ /**
+ * Tests that loggers mentioned in logger elements
+ * use the specified categoryFactory. See bug 33708.
+ */
+ public void testCategoryFactory1() {
+ DOMConfigurator.configure("input/xml/categoryfactory1.xml");
+ //
+ // logger explicitly mentioned in configuration,
+ // should be a CustomLogger
+ Logger logger1 = Logger.getLogger("org.apache.log4j.xml.DOMTestCase.testCategoryFactory1.1");
+ assertTrue(logger1 instanceof CustomLogger);
+ //
+ // logger not explicitly mentioned in configuration,
+ // should use default factory
+ Logger logger2 = Logger.getLogger("org.apache.log4j.xml.DOMTestCase.testCategoryFactory1.2");
+ assertFalse(logger2 instanceof CustomLogger);
+ }
+
+ /**
+ * Tests that loggers mentioned in logger-ref elements
+ * use the specified categoryFactory. See bug 33708.
+ */
+ public void testCategoryFactory2() {
+ DOMConfigurator.configure("input/xml/categoryfactory2.xml");
+ //
+ // logger explicitly mentioned in configuration,
+ // should be a CustomLogger
+ Logger logger1 = Logger.getLogger("org.apache.log4j.xml.DOMTestCase.testCategoryFactory2.1");
+ assertTrue(logger1 instanceof CustomLogger);
+ //
+ // logger not explicitly mentioned in configuration,
+ // should use default factory
+ Logger logger2 = Logger.getLogger("org.apache.log4j.xml.DOMTestCase.testCategoryFactory2.2");
+ assertFalse(logger2 instanceof CustomLogger);
+ }
+
+ /**
+ * Tests that loggers mentioned in logger elements
+ * use the specified loggerFactory. See bug 33708.
+ */
+ public void testLoggerFactory1() {
+ DOMConfigurator.configure("input/xml/loggerfactory1.xml");
+ //
+ // logger explicitly mentioned in configuration,
+ // should be a CustomLogger
+ Logger logger1 = Logger.getLogger("org.apache.log4j.xml.DOMTestCase.testLoggerFactory1.1");
+ assertTrue(logger1 instanceof CustomLogger);
+ //
+ // logger not explicitly mentioned in configuration,
+ // should use default factory
+ Logger logger2 = Logger.getLogger("org.apache.log4j.xml.DOMTestCase.testLoggerFactory1.2");
+ assertFalse(logger2 instanceof CustomLogger);
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org