You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-cvs@jakarta.apache.org by ce...@apache.org on 2001/01/07 22:10:57 UTC
cvs commit: jakarta-log4j/org/apache/log4j/xml DOMConfigurator.java
ceki 01/01/07 13:10:57
Modified: org/apache/log4j BasicConfigurator.java Category.java
Hierarchy.java PropertyConfigurator.java
StressCategory.java
org/apache/log4j/helpers OptionConverter.java
org/apache/log4j/spi Configurator.java
org/apache/log4j/test SysoutConfigurator.java
org/apache/log4j/xml DOMConfigurator.java
Log:
Changed *all* Configurators to be Hierarchy sensitive. The new code compiles but
remains untested.
Revision Changes Path
1.5 +6 -6 jakarta-log4j/org/apache/log4j/BasicConfigurator.java
Index: BasicConfigurator.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/BasicConfigurator.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BasicConfigurator.java 2000/12/22 10:41:29 1.4
+++ BasicConfigurator.java 2001/01/07 21:10:56 1.5
@@ -98,7 +98,7 @@
} else {
try {
Class renderedClass = Class.forName(renderedClassName);
- Category._default.rendererMap.put(renderedClass, renderer);
+ Category.defaultHierarchy.rendererMap.put(renderedClass, renderer);
} catch(ClassNotFoundException e) {
LogLog.error("Could not find class ["+renderedClassName+"].", e);
}
@@ -269,14 +269,14 @@
static
void resetConfiguration() {
- Category._default.getRoot().setPriority(Priority.DEBUG);
- Category._default.root.setResourceBundle(null);
+ Category.defaultHierarchy.getRoot().setPriority(Priority.DEBUG);
+ Category.defaultHierarchy.root.setResourceBundle(null);
Category.disable = Category.DISABLE_OFF;
// the synchronization is needed to prevent JDK 1.2.x hashtable
// surprises
- synchronized(Category._default.ht) {
- Category._default.shutdown(); // nested locks are OK
+ synchronized(Category.defaultHierarchy.ht) {
+ Category.defaultHierarchy.shutdown(); // nested locks are OK
Enumeration cats = Category.getCurrentCategories();
while(cats.hasMoreElements()) {
@@ -286,6 +286,6 @@
c.setResourceBundle(null);
}
}
- Category._default.rendererMap.clear();
+ Category.defaultHierarchy.rendererMap.clear();
}
}
1.6 +10 -10 jakarta-log4j/org/apache/log4j/Category.java
Index: Category.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/Category.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Category.java 2000/12/27 15:25:57 1.5
+++ Category.java 2001/01/07 21:10:56 1.6
@@ -69,13 +69,13 @@
// an undescore.
static
public
- final Hierarchy _default = new Hierarchy( new RootCategory(Priority.DEBUG));
+ final Hierarchy defaultHierarchy = new Hierarchy(new RootCategory(Priority.DEBUG));
protected ResourceBundle resourceBundle;
// Categories need to know what Hierarchy they are in
- Hierarchy myContext;
+ protected Hierarchy myContext;
/**
This string constant is set to <b>log4j.properties</b> the name
@@ -392,7 +392,7 @@
public
static
Category exists(String name) {
- return _default.exists(name);
+ return defaultHierarchy.exists(name);
}
/**
@@ -519,9 +519,9 @@
// The accumlation in v is necessary because not all elements in
// HierarchyMaintainer.ht are Category objects as there might be some
// ProvisionNodes as well.
- Vector v = new Vector(_default.ht.size());
+ Vector v = new Vector(defaultHierarchy.ht.size());
- Enumeration elems = _default.ht.elements();
+ Enumeration elems = defaultHierarchy.ht.elements();
while(elems.hasMoreElements()) {
Object o = elems.nextElement();
if(o instanceof Category) {
@@ -540,7 +540,7 @@
public
static
Hierarchy getDefaultHierarchy() {
- return _default;
+ return defaultHierarchy;
}
@@ -558,7 +558,7 @@
public
static
Category getInstance(String name) {
- return _default.getInstance(name);
+ return defaultHierarchy.getInstance(name);
}
/**
@@ -593,7 +593,7 @@
public
static
Category getInstance(String name, CategoryFactory factory) {
- return _default.getInstance(name, factory);
+ return defaultHierarchy.getInstance(name, factory);
}
@@ -631,7 +631,7 @@
public
static
Category getRoot() {
- return _default.getRoot();
+ return defaultHierarchy.getRoot();
}
/**
@@ -984,7 +984,7 @@
public
static
void shutdown() {
- _default.shutdown();
+ defaultHierarchy.shutdown();
}
1.8 +8 -0 jakarta-log4j/org/apache/log4j/Hierarchy.java
Index: Hierarchy.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/Hierarchy.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Hierarchy.java 2000/12/27 15:25:57 1.7
+++ Hierarchy.java 2001/01/07 21:10:56 1.8
@@ -179,6 +179,14 @@
}
}
+ /**
+ Get the renderer map for this hierarchy.
+ */
+ public
+ RendererMap getRendererMap() {
+ return rendererMap;
+ }
+
/**
Get the root of this hierarchy.
1.5 +14 -15 jakarta-log4j/org/apache/log4j/PropertyConfigurator.java
Index: PropertyConfigurator.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/PropertyConfigurator.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- PropertyConfigurator.java 2000/12/26 21:42:46 1.4
+++ PropertyConfigurator.java 2001/01/07 21:10:56 1.5
@@ -283,7 +283,7 @@
*/
public
- void doConfigure(String configFileName) {
+ void doConfigure(String configFileName, Hierarchy hierarchy) {
Properties props = new Properties();
try {
FileInputStream istream = new FileInputStream(configFileName);
@@ -298,7 +298,7 @@
}
// If we reach here, then the config file is alright.
//debug("Reading configuration.");
- doConfigure(props);
+ doConfigure(props, hierarchy);
}
/**
@@ -306,7 +306,7 @@
static
public
void configure(String configFilename) {
- new PropertyConfigurator().doConfigure(configFilename);
+ new PropertyConfigurator().doConfigure(configFilename, Category.defaultHierarchy);
}
@@ -318,7 +318,7 @@
static
public
void configure(Properties properties) {
- new PropertyConfigurator().doConfigure(properties);
+ new PropertyConfigurator().doConfigure(properties, Category.defaultHierarchy);
}
/**
@@ -327,7 +327,7 @@
See {@link #doConfigure(String)} for the expected format.
*/
public
- void doConfigure(Properties properties) {
+ void doConfigure(Properties properties, Hierarchy hierarchy) {
String value = properties.getProperty(LogLog.CONFIG_DEBUG_KEY);
if(value != null) {
@@ -339,9 +339,9 @@
BasicConfigurator.DISABLE_OVERRIDE_KEY);
BasicConfigurator.overrideAsNeeded(override);
- configureRootCategory(properties);
+ configureRootCategory(properties, hierarchy);
configureCategoryFactory(properties);
- parseCatsAndRenderers(properties);
+ parseCatsAndRenderers(properties, hierarchy);
LogLog.debug("Finished configuring.");
// We don't want to hold references to appenders preventing their
@@ -357,7 +357,7 @@
public
static
void configure(java.net.URL configURL) {
- new PropertyConfigurator().doConfigure(configURL);
+ new PropertyConfigurator().doConfigure(configURL, Category.defaultHierarchy);
}
/**
@@ -398,7 +398,7 @@
Read configuration options from url <code>configURL</code>.
*/
public
- void doConfigure(java.net.URL configURL) {
+ void doConfigure(java.net.URL configURL, Hierarchy hierarchy) {
Properties props = new Properties();
LogLog.debug("Reading configuration from URL " + configURL);
try {
@@ -446,12 +446,12 @@
}
- void configureRootCategory(Properties props) {
+ void configureRootCategory(Properties props, Hierarchy hierarchy) {
String value = OptionConverter.findAndSubst(ROOT_CATEGORY_PREFIX, props);
if(value == null)
LogLog.debug("Could not find root category information. Is this OK?");
else {
- Category root = Category.getRoot();
+ Category root = hierarchy.getRoot();
synchronized(root) {
parseCategory(props, root, ROOT_CATEGORY_PREFIX, INTERNAL_ROOT_NAME,
value);
@@ -464,15 +464,14 @@
Parse non-root elements, such non-root categories and renderers.
*/
protected
- void parseCatsAndRenderers(Properties props) {
+ void parseCatsAndRenderers(Properties props, Hierarchy hierarchy) {
Enumeration enum = props.propertyNames();
while(enum.hasMoreElements()) {
String key = (String) enum.nextElement();
if(key.startsWith(CATEGORY_PREFIX)) {
String categoryName = key.substring(CATEGORY_PREFIX.length());
String value = OptionConverter.findAndSubst(key, props);
- Category cat = Category._default.getInstance(categoryName,
- categoryFactory);
+ Category cat = hierarchy.getInstance(categoryName, categoryFactory);
synchronized(cat) {
parseCategory(props, cat, key, categoryName, value);
parseAdditivityForCategory(props, cat, categoryName);
@@ -616,6 +615,6 @@
<code>filename</code> to reconfigure log4j. */
public
void doOnChange() {
- new PropertyConfigurator().doConfigure(filename);
+ new PropertyConfigurator().doConfigure(filename, Category.defaultHierarchy);
}
}
1.4 +1 -1 jakarta-log4j/org/apache/log4j/StressCategory.java
Index: StressCategory.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/StressCategory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StressCategory.java 2000/12/21 16:22:02 1.3
+++ StressCategory.java 2001/01/07 21:10:56 1.4
@@ -111,7 +111,7 @@
}
test();
// Clear hash table for next round
- Category._default.clear();
+ Category.defaultHierarchy.clear();
}
else {
ct[n] = null;
1.5 +2 -1 jakarta-log4j/org/apache/log4j/helpers/OptionConverter.java
Index: OptionConverter.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/helpers/OptionConverter.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- OptionConverter.java 2000/12/26 23:20:29 1.4
+++ OptionConverter.java 2001/01/07 21:10:56 1.5
@@ -10,6 +10,7 @@
import java.util.Properties;
import java.net.URL;
+import org.apache.log4j.Category;
import org.apache.log4j.spi.Configurator;
import org.apache.log4j.xml.DOMConfigurator;
import org.apache.log4j.PropertyConfigurator;
@@ -330,6 +331,6 @@
}
}
- configurator.doConfigure(url);
+ configurator.doConfigure(url, Category.defaultHierarchy);
}
}
1.4 +9 -5 jakarta-log4j/org/apache/log4j/spi/Configurator.java
Index: Configurator.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/spi/Configurator.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Configurator.java 2000/12/27 15:25:59 1.3
+++ Configurator.java 2001/01/07 21:10:56 1.4
@@ -7,6 +7,7 @@
package org.apache.log4j.spi;
+import org.apache.log4j.Hierarchy;
import java.net.URL;
/**
@@ -14,13 +15,16 @@
@since 1.0
@author Anders Kristensen
- @author Ceki Gulcu
-
*/
public interface Configurator {
/**
- Interprets the specified Properties map and configures
- log4j accordingly.
+ Interpret a resource pointed by a URL and set up log4j accordingly.
+
+ The configuration is done relative to the <code>hierarchy</code>
+ parameter.
+
+ @param url The URL to parse
+ @param hierarchy The hierarchy to operation upon.
*/
- void doConfigure(URL url);
+ void doConfigure(URL url, Hierarchy hierarchy);
}
1.3 +2 -1 jakarta-log4j/org/apache/log4j/test/SysoutConfigurator.java
Index: SysoutConfigurator.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/test/SysoutConfigurator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SysoutConfigurator.java 2000/12/14 21:08:14 1.2
+++ SysoutConfigurator.java 2001/01/07 21:10:56 1.3
@@ -2,6 +2,7 @@
import java.util.Properties;
import org.apache.log4j.Category;
+import org.apache.log4j.Hierarchy;
import org.apache.log4j.spi.Configurator;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.SimpleLayout;
@@ -15,7 +16,7 @@
public class SysoutConfigurator implements Configurator {
public
void
- doConfigure(java.net.URL url) {
+ doConfigure(java.net.URL url, Hierarchy hierarchy) {
Category.getRoot().addAppender(
new FileAppender(
new SimpleLayout(), System.out));
1.5 +24 -32 jakarta-log4j/org/apache/log4j/xml/DOMConfigurator.java
Index: DOMConfigurator.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/xml/DOMConfigurator.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DOMConfigurator.java 2000/12/20 23:48:11 1.4
+++ DOMConfigurator.java 2001/01/07 21:10:57 1.5
@@ -1,5 +1,9 @@
-// Copyright 2000, Ceki Gulcu. All Rights Reserved.
-// See the LICENCE file for the terms of distribution.
+/*
+ * Copyright (C) The Apache Software Foundation. All rights reserved.
+ *
+ * This software is published under the terms of the Apache Software
+ * License version 1.1, a copy of which has been included with this
+ * distribution in the LICENSE.APL file. */
package org.apache.log4j.xml;
@@ -17,6 +21,7 @@
import org.apache.log4j.Appender;
import org.apache.log4j.Layout;
import org.apache.log4j.Priority;
+import org.apache.log4j.Hierarchy;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.spi.Filter;
@@ -269,7 +274,7 @@
Used internally to parse an category element.
*/
protected
- void parseCategory (Element categoryElement) {
+ void parseCategory (Element categoryElement, Hierarchy hierarchy) {
// Create a new org.apache.log4j.Category object from the <category> element.
String catName = categoryElement.getAttribute(NAME_ATTR);
@@ -280,7 +285,7 @@
if(EMPTY_STR.equals(className)) {
LogLog.debug("Retreiving an instance of org.apache.log4j.Category.");
- cat = Category.getInstance(catName);
+ cat = hierarchy.getInstance(catName);
}
else {
LogLog.debug("Desired category sub-class: ["+className+']');
@@ -311,8 +316,8 @@
Used internally to parse the roor category element.
*/
protected
- void parseRoot (Element rootElement) {
- Category root = Category.getRoot();
+ void parseRoot (Element rootElement, Hierarchy hierarchy) {
+ Category root = hierarchy.getRoot();
// category configuration needs to be atomic
synchronized(root) {
parseChildrenOfCategoryElement(rootElement, root, true);
@@ -459,13 +464,12 @@
Configure log4j using a <code>configuration</code> element as
defined in the log4j.dtd.
- <p><b>Note:</b> This public method relies on DOM Level-2 API.
*/
static
public
void configure (Element element) {
DOMConfigurator configurator = new DOMConfigurator();
- configurator.parse(element);
+ configurator.parse(element, Category.getDefaultHierarchy());
}
/**
@@ -473,11 +477,6 @@
default delay as defined by {@link FileWatchdog#DEFAULT_DELAY} is
used.
- <p><b>Note:</b> This public method relies on DOM Level-2 API, and a
- JAXP compliant parser. At the time of this writing only the
- Apache Xerces parser fulfills both requirements.
-
-
@param configFilename A log4j configuration file in XML format.
*/
@@ -497,11 +496,6 @@
argument. If a change or file creation is detected, then
<code>configFilename</code> is read to configure log4j.
- <p><b>Note:</b> This public method relies on DOM Level-2 API, and a
- JAXP compliant parser. At the time of this writing only the
- Apache Xerces parser fulfills both requirements.
-
-
@param configFilename A log4j configuration file in XML format.
@param delay The delay in milliseconds to wait between each check.
*/
@@ -514,18 +508,18 @@
}
public
- void doConfigure(String filename) {
+ void doConfigure(String filename, Hierarchy hierarchy) {
try {
- doConfigure(new FileInputStream(filename));
+ doConfigure(new FileInputStream(filename), hierarchy);
} catch(IOException e) {
LogLog.error("Could not open ["+filename+"].", e);
}
}
public
- void doConfigure(URL url) {
+ void doConfigure(URL url, Hierarchy hierarchy) {
try {
- doConfigure(url.openStream());
+ doConfigure(url.openStream(), hierarchy);
} catch(IOException e) {
LogLog.error("Could not open ["+url+"].", e);
}
@@ -536,12 +530,10 @@
Configure log4j by reading in a log4j.dtd compliant XML
configuration file.
- <p><b>Note:</b> This public method relies on DOM Level-2 API,
- and a JAXP compliant parser. At the time of this writing only
- the Apache Xerces parser fulfills both requirements.
*/
public
- void doConfigure(InputStream input) throws FactoryConfigurationError {
+ void doConfigure(InputStream input, Hierarchy hierarchy)
+ throws FactoryConfigurationError {
DocumentBuilderFactory dbf = null;
try {
LogLog.debug("System property is :"+System.getProperty(dbfKey));
@@ -572,7 +564,7 @@
inputSource.setSystemId(dtdURL.toString());
}
Document doc = docBuilder.parse(inputSource);
- DOMConfigurator.configure(doc.getDocumentElement());
+ parse(doc.getDocumentElement(), hierarchy);
} catch (Exception e) {
// I know this is miserable...
LogLog.error("Could not parse input stream ["+input+"].", e);
@@ -587,7 +579,7 @@
static
public
void configure(String filename) throws FactoryConfigurationError {
- new DOMConfigurator().doConfigure(filename);
+ new DOMConfigurator().doConfigure(filename, Category.getDefaultHierarchy());
}
/**
@@ -597,7 +589,7 @@
*/
protected
- void parse(Element element) {
+ void parse(Element element, Hierarchy hierarchy) {
if (!element.getTagName().equals(CONFIGURATION_TAG)) {
LogLog.error("DOM element is not a <configuration> element");
@@ -641,9 +633,9 @@
String tagName = currentElement.getTagName();
if (tagName.equals(CATEGORY)) {
- parseCategory(currentElement);
+ parseCategory(currentElement, hierarchy);
} else if (tagName.equals(ROOT_TAG)) {
- parseRoot(currentElement);
+ parseRoot(currentElement, hierarchy);
} else if(tagName.equals(RENDERER_TAG)) {
parserRenderer(currentElement);
}
@@ -664,6 +656,6 @@
<code>filename</code> to reconfigure log4j. */
public
void doOnChange() {
- new DOMConfigurator().doConfigure(filename);
+ new DOMConfigurator().doConfigure(filename, Category.getDefaultHierarchy());
}
}