Author: carnold
Date: Wed Aug 22 14:15:35 2007
New Revision: 568750
URL: http://svn.apache.org/viewvc?rev=568750&view=rev
Log:
Bug 17531: Add reset option to PropertyConfigurator and DOMConfigurator
Added:
logging/log4j/trunk/tests/input/xml/testReset.xml
Modified:
logging/log4j/trunk/src/changes/changes.xml
logging/log4j/trunk/src/main/java/org/apache/log4j/PropertyConfigurator.java
logging/log4j/trunk/src/main/java/org/apache/log4j/xml/DOMConfigurator.java
logging/log4j/trunk/src/main/javadoc/org/apache/log4j/xml/log4j.dtd
logging/log4j/trunk/src/main/resources/org/apache/log4j/xml/log4j.dtd
logging/log4j/trunk/tests/src/java/org/apache/log4j/PropertyConfiguratorTest.java
logging/log4j/trunk/tests/src/java/org/apache/log4j/xml/DOMTestCase.java
Modified: logging/log4j/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/logging/log4j/trunk/src/changes/changes.xml?rev=568750&r1=568749&r2=568750&view=diff
==============================================================================
--- logging/log4j/trunk/src/changes/changes.xml (original)
+++ logging/log4j/trunk/src/changes/changes.xml Wed Aug 22 14:15:35 2007
@@ -22,7 +22,8 @@
<body>
<release version="1.2.15" date="2007-06-27" description="SyslogAppender
enhancements, NTEventLogAppender and Maven build.">
- <action action="fix" issue="14350">Error message always logged to
LogLog when calling close on TelnetAppender.</action>
+ <action action="add" issue="17531">Add reset option to
PropertyConfigurator and DOMConfigurator.</action>
+ <action action="fix" issue="14350">Error message always logged to
LogLog when calling close on TelnetAppender.</action>
<action action="add" issue="32572">Add configurable triggeringPolicy
for SMTPAppender.</action>
<action action="fix" issue="43181">NullPointerException in MDC on
Tomcat reload.</action>
<action action="fix" issue="34874">Notice to use UTF-8 or UTF-16
encoding added to XML and HTMLLayout javadoc.</action>
Modified:
logging/log4j/trunk/src/main/java/org/apache/log4j/PropertyConfigurator.java
URL:
http://svn.apache.org/viewvc/logging/log4j/trunk/src/main/java/org/apache/log4j/PropertyConfigurator.java?rev=568750&r1=568749&r2=568750&view=diff
==============================================================================
---
logging/log4j/trunk/src/main/java/org/apache/log4j/PropertyConfigurator.java
(original)
+++
logging/log4j/trunk/src/main/java/org/apache/log4j/PropertyConfigurator.java
Wed Aug 22 14:15:35 2007
@@ -103,6 +103,11 @@
LoggerFactory}. Currently set to "<code>log4j.loggerFactory</code>". */
public static final String LOGGER_FACTORY_KEY = "log4j.loggerFactory";
+ /**
+ * If property set to true, then hierarchy will be reset before
configuration.
+ */
+ private static final String RESET_KEY = "log4j.reset";
+
static final private String INTERNAL_ROOT_NAME = "root";
/**
@@ -230,6 +235,11 @@
The usage of custom logger factories is discouraged and no longer
documented.
+ <h3>Resetting Hierarchy</h3>
+
+ The hierarchy will be reset before configuration when
+ log4j.reset=true is present in the properties file.
+
<h3>Example</h3>
<p>An example configuration is given below. Other configuration
@@ -400,7 +410,6 @@
*/
public
void doConfigure(Properties properties, LoggerRepository hierarchy) {
-
String value = properties.getProperty(LogLog.DEBUG_KEY);
if(value == null) {
value = properties.getProperty("log4j.configDebug");
@@ -410,6 +419,14 @@
if(value != null) {
LogLog.setInternalDebugging(OptionConverter.toBoolean(value, true));
+ }
+
+ //
+ // if log4j.reset=true then
+ // reset hierarchy
+ String reset = properties.getProperty(RESET_KEY);
+ if (reset != null && OptionConverter.toBoolean(reset, false)) {
+ hierarchy.resetConfiguration();
}
String thresholdStr = OptionConverter.findAndSubst(THRESHOLD_PREFIX,
Modified:
logging/log4j/trunk/src/main/java/org/apache/log4j/xml/DOMConfigurator.java
URL:
http://svn.apache.org/viewvc/logging/log4j/trunk/src/main/java/org/apache/log4j/xml/DOMConfigurator.java?rev=568750&r1=568749&r2=568750&view=diff
==============================================================================
--- logging/log4j/trunk/src/main/java/org/apache/log4j/xml/DOMConfigurator.java
(original)
+++ logging/log4j/trunk/src/main/java/org/apache/log4j/xml/DOMConfigurator.java
Wed Aug 22 14:15:35 2007
@@ -111,6 +111,7 @@
static final String THRESHOLD_ATTR = "threshold";
static final String CONFIG_DEBUG_ATTR = "configDebug";
static final String INTERNAL_DEBUG_ATTR = "debug";
+ private static final String RESET_ATTR = "reset";
static final String RENDERING_CLASS_ATTR = "renderingClass";
static final String RENDERED_CLASS_ATTR = "renderedClass";
@@ -842,6 +843,7 @@
}
}
+
String debugAttrib = subst(element.getAttribute(INTERNAL_DEBUG_ATTR));
LogLog.debug("debug attribute= \"" + debugAttrib +"\".");
@@ -852,6 +854,19 @@
} else {
LogLog.debug("Ignoring " + INTERNAL_DEBUG_ATTR + " attribute.");
}
+
+ //
+ // reset repository before configuration if reset="true"
+ // on configuration element.
+ //
+ String resetAttrib = subst(element.getAttribute(RESET_ATTR));
+ LogLog.debug("reset attribute= \"" + resetAttrib +"\".");
+ if(!("".equals(resetAttrib))) {
+ if (OptionConverter.toBoolean(resetAttrib, false)) {
+ repository.resetConfiguration();
+ }
+ }
+
String confDebug = subst(element.getAttribute(CONFIG_DEBUG_ATTR));
Modified: logging/log4j/trunk/src/main/javadoc/org/apache/log4j/xml/log4j.dtd
URL:
http://svn.apache.org/viewvc/logging/log4j/trunk/src/main/javadoc/org/apache/log4j/xml/log4j.dtd?rev=568750&r1=568749&r2=568750&view=diff
==============================================================================
--- logging/log4j/trunk/src/main/javadoc/org/apache/log4j/xml/log4j.dtd
(original)
+++ logging/log4j/trunk/src/main/javadoc/org/apache/log4j/xml/log4j.dtd Wed Aug
22 14:15:35 2007
@@ -14,7 +14,6 @@
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.
-
-->
<!-- Authors: Chris Taylor, Ceki Gulcu. -->
@@ -45,6 +44,7 @@
xmlns:log4j CDATA #FIXED "http://jakarta.apache.org/log4j/"
threshold (all|trace|debug|info|warn|error|fatal|off|null)
"null"
debug (true|false|null) "null"
+ reset (true|false) "false"
>
<!-- renderer elements allow the user to customize the conversion of -->
@@ -154,12 +154,12 @@
<!ELEMENT connectionSource (dataSource?, param*)>
<!ATTLIST connectionSource
- class CDATA #REQUIRED
+ class CDATA #REQUIRED
>
<!ELEMENT dataSource (param*)>
<!ATTLIST dataSource
- class CDATA #REQUIRED
+ class CDATA #REQUIRED
>
<!ELEMENT triggeringPolicy ((param|filter)*)>
@@ -194,7 +194,7 @@
<!ELEMENT log4j:event (log4j:message, log4j:NDC?, log4j:throwable?,
- log4j:locationInfo?) >
+ log4j:locationInfo?, log4j:properties?) >
<!-- The timestamp format is application dependent. -->
<!ATTLIST log4j:event
@@ -202,6 +202,7 @@
level CDATA #REQUIRED
thread CDATA #REQUIRED
timestamp CDATA #REQUIRED
+ time CDATA #IMPLIED
>
<!ELEMENT log4j:message (#PCDATA)>
@@ -215,4 +216,12 @@
method CDATA #REQUIRED
file CDATA #REQUIRED
line CDATA #REQUIRED
+>
+
+<!ELEMENT log4j:properties (log4j:data*)>
+
+<!ELEMENT log4j:data EMPTY>
+<!ATTLIST log4j:data
+ name CDATA #REQUIRED
+ value CDATA #REQUIRED
>
Modified: logging/log4j/trunk/src/main/resources/org/apache/log4j/xml/log4j.dtd
URL:
http://svn.apache.org/viewvc/logging/log4j/trunk/src/main/resources/org/apache/log4j/xml/log4j.dtd?rev=568750&r1=568749&r2=568750&view=diff
==============================================================================
--- logging/log4j/trunk/src/main/resources/org/apache/log4j/xml/log4j.dtd
(original)
+++ logging/log4j/trunk/src/main/resources/org/apache/log4j/xml/log4j.dtd Wed
Aug 22 14:15:35 2007
@@ -44,6 +44,7 @@
xmlns:log4j CDATA #FIXED "http://jakarta.apache.org/log4j/"
threshold (all|trace|debug|info|warn|error|fatal|off|null)
"null"
debug (true|false|null) "null"
+ reset (true|false) "false"
>
<!-- renderer elements allow the user to customize the conversion of -->
Added: logging/log4j/trunk/tests/input/xml/testReset.xml
URL:
http://svn.apache.org/viewvc/logging/log4j/trunk/tests/input/xml/testReset.xml?rev=568750&view=auto
==============================================================================
--- logging/log4j/trunk/tests/input/xml/testReset.xml (added)
+++ logging/log4j/trunk/tests/input/xml/testReset.xml Wed Aug 22 14:15:35 2007
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ 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.
+-->
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
reset="true">
+ <appender name="A1" class="org.apache.log4j.VectorAppender"/>
+ <logger name="org.apache.log4j.xml">
+ <level value="trace" />
+ <appender-ref ref="A1" />
+ </logger>
+
+</log4j:configuration>
Modified:
logging/log4j/trunk/tests/src/java/org/apache/log4j/PropertyConfiguratorTest.java
URL:
http://svn.apache.org/viewvc/logging/log4j/trunk/tests/src/java/org/apache/log4j/PropertyConfiguratorTest.java?rev=568750&r1=568749&r2=568750&view=diff
==============================================================================
---
logging/log4j/trunk/tests/src/java/org/apache/log4j/PropertyConfiguratorTest.java
(original)
+++
logging/log4j/trunk/tests/src/java/org/apache/log4j/PropertyConfiguratorTest.java
Wed Aug 22 14:15:35 2007
@@ -15,10 +15,14 @@
* limitations under the License.
*/
package org.apache.log4j;
-import java.io.*;
-import junit.framework.*;
-import org.apache.log4j.PropertyConfigurator;
+
+import junit.framework.TestCase;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
import java.net.URL;
+import java.util.Properties;
/**
* Test property configurator.
@@ -77,6 +81,21 @@
PropertyConfigurator.configure(url);
assertTrue(file.delete());
assertFalse(file.exists());
+ }
+
+ /**
+ * Test processing of log4j.reset property, see bug 17531.
+ *
+ */
+ public void testReset() {
+ VectorAppender appender = new VectorAppender();
+ appender.setName("A1");
+ Logger.getRootLogger().addAppender(appender);
+ Properties props = new Properties();
+ props.put("log4j.reset", "true");
+ PropertyConfigurator.configure(props);
+ assertNull(Logger.getRootLogger().getAppender("A1"));
+ LogManager.resetConfiguration();
}
}
Modified:
logging/log4j/trunk/tests/src/java/org/apache/log4j/xml/DOMTestCase.java
URL:
http://svn.apache.org/viewvc/logging/log4j/trunk/tests/src/java/org/apache/log4j/xml/DOMTestCase.java?rev=568750&r1=568749&r2=568750&view=diff
==============================================================================
--- logging/log4j/trunk/tests/src/java/org/apache/log4j/xml/DOMTestCase.java
(original)
+++ logging/log4j/trunk/tests/src/java/org/apache/log4j/xml/DOMTestCase.java
Wed Aug 22 14:15:35 2007
@@ -21,6 +21,7 @@
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
+import org.apache.log4j.VectorAppender;
import org.apache.log4j.spi.ErrorHandler;
import org.apache.log4j.spi.LoggerFactory;
import org.apache.log4j.spi.LoggingEvent;
@@ -283,6 +284,19 @@
// should use default factory
Logger logger2 =
Logger.getLogger("org.apache.log4j.xml.DOMTestCase.testLoggerFactory1.2");
assertFalse(logger2 instanceof CustomLogger);
+ }
+
+ /**
+ * Tests that reset="true" on log4j:configuration element resets
+ * repository before configuration.
+ * @throws Exception thrown on error.
+ */
+ public void testReset() throws Exception {
+ VectorAppender appender = new VectorAppender();
+ appender.setName("V1");
+ Logger.getRootLogger().addAppender(appender);
+ DOMConfigurator.configure("input/xml/testReset.xml");
+ assertNull(Logger.getRootLogger().getAppender("V1"));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]