From 549db6b06922adebd36ffcdc1e71029ca7d78a33 Mon Sep 17 00:00:00 2001 From: Simon Kitching Date: Thu, 23 Jun 2005 05:40:32 +0000 Subject: [PATCH] Split Log4JLogger into Log4J12Logger and Log4J13Logger git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@193079 13f79535-47bb-0310-9956-ffa450edef68 --- build.properties.sample | 8 +- build.xml | 170 ++++++---- .../commons/logging/impl/Log4J12Logger.java | 294 ++++++++++++++++++ .../{Log4JLogger.java => Log4J13Logger.java} | 142 +++------ .../commons/logging/impl/Log4jFactory.java | 163 ---------- .../commons/logging/impl/LogFactoryImpl.java | 3 +- .../logging/log4j/CustomConfigTestCase.java | 2 +- .../logging/log4j/DefaultConfigTestCase.java | 2 +- 8 files changed, 463 insertions(+), 321 deletions(-) create mode 100644 src/java/org/apache/commons/logging/impl/Log4J12Logger.java rename src/java/org/apache/commons/logging/impl/{Log4JLogger.java => Log4J13Logger.java} (55%) delete mode 100644 src/java/org/apache/commons/logging/impl/Log4jFactory.java diff --git a/build.properties.sample b/build.properties.sample index 6387e64..e4c8e03 100644 --- a/build.properties.sample +++ b/build.properties.sample @@ -12,11 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -# log4j.jar - log4j classes (see http://jakarta.apache.org/log4j) -log4j.jar=/java/log4j/log4j.jar +# Apache Log4j 1.2.x series +log4j12.jar=/java/log4j/log4j-1.2.9.jar -# Used for testing against older 1.2.x Log4J versions -log4j12.jar=/java/log4j/log4j-1.2.7.jar +# Apache Log4j 1.3.x series +log4j13.jar=/java/log4j/log4j-1.3.0.jar # logkit.jar - Avalon LogKit classes (see http://jakarta.apache.org/avalon) logkit.jar=/java/logkit/logkit.jar diff --git a/build.xml b/build.xml index 5865aa5..d7cf6ff 100644 --- a/build.xml +++ b/build.xml @@ -46,7 +46,8 @@ - + + @@ -113,7 +114,6 @@ - @@ -128,7 +128,6 @@ - @@ -143,11 +142,11 @@ - + - + @@ -186,7 +185,8 @@ description="Prepare build directory"> - Log4j: ${log4j.jar} + Log4j12: ${log4j12.jar} + Log4j13: ${log4j13.jar} LogKit: ${logkit.jar} Avalon-Framework: ${avalon-framework.jar} @@ -215,21 +215,30 @@ - + + + + + - + *** WARNING *** - Log4j not found: Cannot Build Log4jLogger + Log4j12 not found: Cannot Build Log4J12Logger + + + + + + *** WARNING *** + Log4j13 not found: Cannot Build Log4J13Logger @@ -254,23 +263,25 @@ - + *** WARNING *** Log4J 1.2.x Jar not found: Cannot execute 1.2.x tests - + - + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -344,13 +396,13 @@ - + - + @@ -389,9 +441,9 @@ basedir="${build.home}/tests" manifest="${build.home}/conf/MANIFEST.MF"> + if="log4j12.present"/> + if="log4j12.present"/> - + @@ -660,13 +712,13 @@ limitations under the License.-->'> - - + @@ -674,21 +726,21 @@ limitations under the License.-->'> - + - + + value="org.apache.commons.logging.impl.Log4J12Logger"/> - + - + @@ -696,30 +748,30 @@ limitations under the License.-->'> - + - + + value="org.apache.commons.logging.impl.Log4J12Logger"/> - + + value="org.apache.commons.logging.impl.Log4J12Logger"/> - + - + @@ -733,7 +785,7 @@ limitations under the License.-->'> - + @@ -745,16 +797,16 @@ limitations under the License.-->'> - + - + + value="org.apache.commons.logging.impl.Log4J12Logger"/> @@ -765,7 +817,7 @@ limitations under the License.-->'> - + @@ -779,7 +831,7 @@ limitations under the License.-->'> - + @@ -791,16 +843,16 @@ limitations under the License.-->'> - + - + + value="org.apache.commons.logging.impl.Log4J12Logger"/> @@ -885,10 +937,10 @@ limitations under the License.-->'> - + + value="org.apache.commons.logging.impl.Log4J12Logger"/> @@ -907,10 +959,10 @@ limitations under the License.-->'> - + + value="org.apache.commons.logging.impl.Log4J12Logger"/> @@ -918,7 +970,7 @@ limitations under the License.-->'> + value="org.apache.commons.logging.impl.Log4J12Logger"/> @@ -927,7 +979,7 @@ limitations under the License.-->'> - + @@ -941,7 +993,7 @@ limitations under the License.-->'> - + @@ -953,16 +1005,16 @@ limitations under the License.-->'> - + - + + value="org.apache.commons.logging.impl.Log4J12Logger"/> @@ -999,7 +1051,7 @@ limitations under the License.-->'> - + @@ -1008,7 +1060,7 @@ limitations under the License.-->'> + value="org.apache.commons.logging.impl.Log4J12Logger"/> diff --git a/src/java/org/apache/commons/logging/impl/Log4J12Logger.java b/src/java/org/apache/commons/logging/impl/Log4J12Logger.java new file mode 100644 index 0000000..14e42de --- /dev/null +++ b/src/java/org/apache/commons/logging/impl/Log4J12Logger.java @@ -0,0 +1,294 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed 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. + */ + + +package org.apache.commons.logging.impl; + +import java.io.Serializable; +import org.apache.commons.logging.Log; +import org.apache.log4j.Logger; +import org.apache.log4j.Priority; +import org.apache.log4j.Level; + +/** + * Implementation of {@link Log} that maps directly to a + * Logger for log4J version 1.2. + *

+ * Initial configuration of the corresponding Logger instances should be done + * in the usual manner, as outlined in the Log4J documentation. + *

+ * The reason this logger is distinct from the 1.3 logger is that in version 1.2 + * of Log4J: + *

    + *
  • class Logger takes Priority parameters not Level parameters. + *
  • class Level extends Priority + *
+ * Log4J1.3 is expected to change Level so it no longer extends Priority, which is + * a non-binary-compatible change. The class generated by compiling this code against + * log4j 1.2 will therefore not run against log4j 1.3. + * + * @author Scott Sanders + * @author Rod Waldhoff + * @author Robert Burrell Donkin + * @version $Id$ + */ + +public class Log4J12Logger implements Log, Serializable { + + // ------------------------------------------------------------- Attributes + + /** The fully qualified name of the Log4J12Logger class. */ + private static final String FQCN = Log4J12Logger.class.getName(); + + /** Log to this logger */ + private transient Logger logger = null; + + /** Logger name */ + private String name = null; + + private static Priority traceLevel; + + // ------------------------------------------------------------ + // Static Initializer. + // + // Note that this must come after the static variable declarations + // otherwise initialiser expressions associated with those variables + // will override any settings done here. + // + // Verify that log4j is available, and that it is version 1.2. + // If an ExceptionInInitializerError is generated, then LogFactoryImpl + // will treat that as meaning that the appropriate underlying logging + // library is just not present - if discovery is in progress then + // discovery will continue. + // ------------------------------------------------------------ + + static { + if (!Priority.class.isAssignableFrom(Level.class)) { + // nope, this is log4j 1.3, so force an ExceptionInInitializerError + throw new InstantiationError("Log4J 1.2 not available"); + } + + // Releases of log4j1.2 >= 1.2.12 have Priority.TRACE available, earlier + // versions do not. If TRACE is not available, then we have to map + // calls to Log.trace(...) onto the DEBUG level. + + try { + traceLevel = (Priority) Priority.class.getDeclaredField("TRACE").get(null); + } catch(Exception ex) { + // ok, trace not available + traceLevel = Priority.DEBUG; + } + } + + + // ------------------------------------------------------------ Constructor + + public Log4J12Logger() { + } + + + /** + * Base constructor. + */ + public Log4J12Logger(String name) { + this.name = name; + this.logger = getLogger(); + } + + /** For use with a log4j factory. + */ + public Log4J12Logger(Logger logger ) { + this.name = logger.getName(); + this.logger=logger; + } + + + // --------------------------------------------------------- + // Implementation + // + // Note that in the methods below the Priority class is used to define + // levels even though the Level class is supported in 1.2. This is done + // so that at compile time the call definitely resolves to a call to + // a method that takes a Priority rather than one that takes a Level. + // + // The Category class (and hence its subclass Logger) in version 1.2 only + // has methods that take Priority objects. The Category class (and hence + // Logger class) in version 1.3 has methods that take both Priority and + // Level objects. This means that if we use Level here, and compile + // against log4j 1.3 then calls would be bound to the versions of + // methods taking Level objects and then would fail to run against + // version 1.2 of log4j. + // --------------------------------------------------------- + + + /** + * Log a message to the Log4j Logger with TRACE priority. + * When using a log4j version that does not support the TRACE + * level, the message will be logged at the DEBUG level. + */ + public void trace(Object message) { + getLogger().log(FQCN, traceLevel, message, null ); + } + + + /** + * Log an error to the Log4j Logger with TRACE priority. + * When using a log4j version that does not support the TRACE + * level, the message will be logged at the DEBUG level. + */ + public void trace(Object message, Throwable t) { + getLogger().log(FQCN, traceLevel, message, t ); + } + + + /** + * Log a message to the Log4j Logger with DEBUG priority. + */ + public void debug(Object message) { + getLogger().log(FQCN, Priority.DEBUG, message, null ); + } + + /** + * Log an error to the Log4j Logger with DEBUG priority. + */ + public void debug(Object message, Throwable t) { + getLogger().log(FQCN, Priority.DEBUG, message, t ); + } + + + /** + * Log a message to the Log4j Logger with INFO priority. + */ + public void info(Object message) { + getLogger().log(FQCN, Priority.INFO, message, null ); + } + + + /** + * Log an error to the Log4j Logger with INFO priority. + */ + public void info(Object message, Throwable t) { + getLogger().log(FQCN, Priority.INFO, message, t ); + } + + + /** + * Log a message to the Log4j Logger with WARN priority. + */ + public void warn(Object message) { + getLogger().log(FQCN, Priority.WARN, message, null ); + } + + + /** + * Log an error to the Log4j Logger with WARN priority. + */ + public void warn(Object message, Throwable t) { + getLogger().log(FQCN, Priority.WARN, message, t ); + } + + + /** + * Log a message to the Log4j Logger with ERROR priority. + */ + public void error(Object message) { + getLogger().log(FQCN, Priority.ERROR, message, null ); + } + + + /** + * Log an error to the Log4j Logger with ERROR priority. + */ + public void error(Object message, Throwable t) { + getLogger().log(FQCN, Priority.ERROR, message, t ); + } + + + /** + * Log a message to the Log4j Logger with FATAL priority. + */ + public void fatal(Object message) { + getLogger().log(FQCN, Priority.FATAL, message, null ); + } + + + /** + * Log an error to the Log4j Logger with FATAL priority. + */ + public void fatal(Object message, Throwable t) { + getLogger().log(FQCN, Priority.FATAL, message, t ); + } + + + /** + * Return the native Logger instance we are using. + */ + public Logger getLogger() { + if (logger == null) { + logger = Logger.getLogger(name); + } + return (this.logger); + } + + + /** + * Check whether the Log4j Logger used is enabled for DEBUG priority. + */ + public boolean isDebugEnabled() { + return getLogger().isDebugEnabled(); + } + + + /** + * Check whether the Log4j Logger used is enabled for ERROR priority. + */ + public boolean isErrorEnabled() { + return getLogger().isEnabledFor(Priority.ERROR); + } + + + /** + * Check whether the Log4j Logger used is enabled for FATAL priority. + */ + public boolean isFatalEnabled() { + return getLogger().isEnabledFor(Priority.FATAL); + } + + + /** + * Check whether the Log4j Logger used is enabled for INFO priority. + */ + public boolean isInfoEnabled() { + return getLogger().isInfoEnabled(); + } + + + /** + * Check whether the Log4j Logger used is enabled for TRACE priority. + * When using a log4j version that does not support the TRACE level, this call + * will report whether DEBUG is enabled or not. + */ + public boolean isTraceEnabled() { + return getLogger().isEnabledFor(traceLevel); + } + + /** + * Check whether the Log4j Logger used is enabled for WARN priority. + */ + public boolean isWarnEnabled() { + return getLogger().isEnabledFor(Priority.WARN); + } +} diff --git a/src/java/org/apache/commons/logging/impl/Log4JLogger.java b/src/java/org/apache/commons/logging/impl/Log4J13Logger.java similarity index 55% rename from src/java/org/apache/commons/logging/impl/Log4JLogger.java rename to src/java/org/apache/commons/logging/impl/Log4J13Logger.java index adbc093..ac770ff 100644 --- a/src/java/org/apache/commons/logging/impl/Log4JLogger.java +++ b/src/java/org/apache/commons/logging/impl/Log4J13Logger.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2004 The Apache Software Foundation. + * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,30 +20,51 @@ package org.apache.commons.logging.impl; import java.io.Serializable; import org.apache.commons.logging.Log; import org.apache.log4j.Logger; -import org.apache.log4j.Priority; import org.apache.log4j.Level; /** - *

Implementation of {@link Log} that maps directly to a Log4J - * Logger. Initial configuration of the corresponding - * Logger instances should be done in the usual manner, as outlined in - * the Log4J documentation.

+ * Implementation of {@link Log} that maps directly to a + * Logger for log4J version 1.3 or later. + *

+ * Initial configuration of the corresponding Logger instances should be done + * in the usual manner, as outlined in the Log4J documentation. + *

+ * The reason this logger is distinct from the 1.2 logger is that in version 1.3 + * of Log4J, classes Logger and Level should be used. However code that uses + * those classes and is compiled against log4j1.2 will not run against 1.3. And + * code that uses those classes and is compiled against log4j1.3 will not run + * against 1.2. * * @author Scott Sanders * @author Rod Waldhoff * @author Robert Burrell Donkin * @version $Id$ */ -public class Log4JLogger implements Log, Serializable { +public class Log4J13Logger implements Log, Serializable { + // Verify that log4j is available, and that it is version 1.3 or later. + // If an ExceptionInInitializerError is generated, then LogFactoryImpl + // will treat that as meaning that the appropriate underlying logging + // library is just not present - if discovery is in progress then + // discovery will continue. + // + // Note that in log4j 1.2, Priority is effectively deprecated. Its + // replacement, Level, extends Priority. In log4j 1.3, Priority is still + // included but instead extends Level. In later versions, Priority may + // not be included at all. + static { + Class levelSuperclass = Level.class.getSuperclass(); + if (levelSuperclass.getName().equals("org.apache.log4j.Priority")) { + // nope, this is log4j 1.2, so force an ExceptionInInitializerError + throw new InstantiationError("Log4J 1.3 not available"); + } + } // ------------------------------------------------------------- Attributes /** The fully qualified name of the Log4JLogger class. */ - private static final String FQCN = Log4JLogger.class.getName(); + private static final String FQCN = Log4J13Logger.class.getName(); - private static final boolean is12 = Priority.class.isAssignableFrom(Level.class); - /** Log to this logger */ private transient Logger logger = null; @@ -53,21 +74,21 @@ public class Log4JLogger implements Log, Serializable { // ------------------------------------------------------------ Constructor - public Log4JLogger() { + public Log4J13Logger() { } /** * Base constructor. */ - public Log4JLogger(String name) { + public Log4J13Logger(String name) { this.name = name; this.logger = getLogger(); } /** For use with a log4j factory. */ - public Log4JLogger(Logger logger ) { + public Log4J13Logger(Logger logger ) { this.name = logger.getName(); this.logger=logger; } @@ -78,27 +99,17 @@ public class Log4JLogger implements Log, Serializable { /** * Log a message to the Log4j Logger with TRACE priority. - * Currently logs to DEBUG level in Log4J. */ public void trace(Object message) { - if(is12) { - getLogger().log(FQCN, (Priority) Level.DEBUG, message, null ); - } else { - getLogger().log(FQCN, Level.DEBUG, message, null ); - } + getLogger().log(FQCN, Level.TRACE, message, null ); } /** * Log an error to the Log4j Logger with TRACE priority. - * Currently logs to DEBUG level in Log4J. */ public void trace(Object message, Throwable t) { - if(is12) { - getLogger().log(FQCN, (Priority) Level.DEBUG, message, t ); - } else { - getLogger().log(FQCN, Level.DEBUG, message, t ); - } + getLogger().log(FQCN, Level.TRACE, message, t ); } @@ -106,22 +117,14 @@ public class Log4JLogger implements Log, Serializable { * Log a message to the Log4j Logger with DEBUG priority. */ public void debug(Object message) { - if(is12) { - getLogger().log(FQCN, (Priority) Level.DEBUG, message, null ); - } else { - getLogger().log(FQCN, Level.DEBUG, message, null ); - } + getLogger().log(FQCN, Level.DEBUG, message, null ); } /** * Log an error to the Log4j Logger with DEBUG priority. */ public void debug(Object message, Throwable t) { - if(is12) { - getLogger().log(FQCN, (Priority) Level.DEBUG, message, t ); - } else { - getLogger().log(FQCN, Level.DEBUG, message, t ); - } + getLogger().log(FQCN, Level.DEBUG, message, t ); } @@ -129,11 +132,7 @@ public class Log4JLogger implements Log, Serializable { * Log a message to the Log4j Logger with INFO priority. */ public void info(Object message) { - if(is12) { - getLogger().log(FQCN, (Priority) Level.INFO, message, null ); - } else { - getLogger().log(FQCN, Level.INFO, message, null ); - } + getLogger().log(FQCN, Level.INFO, message, null ); } @@ -141,11 +140,7 @@ public class Log4JLogger implements Log, Serializable { * Log an error to the Log4j Logger with INFO priority. */ public void info(Object message, Throwable t) { - if(is12) { - getLogger().log(FQCN, (Priority) Level.INFO, message, t ); - } else { - getLogger().log(FQCN, Level.INFO, message, t ); - } + getLogger().log(FQCN, Level.INFO, message, t ); } @@ -153,11 +148,7 @@ public class Log4JLogger implements Log, Serializable { * Log a message to the Log4j Logger with WARN priority. */ public void warn(Object message) { - if(is12) { - getLogger().log(FQCN, (Priority) Level.WARN, message, null ); - } else { - getLogger().log(FQCN, Level.WARN, message, null ); - } + getLogger().log(FQCN, Level.WARN, message, null ); } @@ -165,11 +156,7 @@ public class Log4JLogger implements Log, Serializable { * Log an error to the Log4j Logger with WARN priority. */ public void warn(Object message, Throwable t) { - if(is12) { - getLogger().log(FQCN, (Priority) Level.WARN, message, t ); - } else { - getLogger().log(FQCN, Level.WARN, message, t ); - } + getLogger().log(FQCN, Level.WARN, message, t ); } @@ -177,11 +164,7 @@ public class Log4JLogger implements Log, Serializable { * Log a message to the Log4j Logger with ERROR priority. */ public void error(Object message) { - if(is12) { - getLogger().log(FQCN, (Priority) Level.ERROR, message, null ); - } else { - getLogger().log(FQCN, Level.ERROR, message, null ); - } + getLogger().log(FQCN, Level.ERROR, message, null ); } @@ -189,11 +172,7 @@ public class Log4JLogger implements Log, Serializable { * Log an error to the Log4j Logger with ERROR priority. */ public void error(Object message, Throwable t) { - if(is12) { - getLogger().log(FQCN, (Priority) Level.ERROR, message, t ); - } else { - getLogger().log(FQCN, Level.ERROR, message, t ); - } + getLogger().log(FQCN, Level.ERROR, message, t ); } @@ -201,11 +180,7 @@ public class Log4JLogger implements Log, Serializable { * Log a message to the Log4j Logger with FATAL priority. */ public void fatal(Object message) { - if(is12) { - getLogger().log(FQCN, (Priority) Level.FATAL, message, null ); - } else { - getLogger().log(FQCN, Level.FATAL, message, null ); - } + getLogger().log(FQCN, Level.FATAL, message, null ); } @@ -213,11 +188,7 @@ public class Log4JLogger implements Log, Serializable { * Log an error to the Log4j Logger with FATAL priority. */ public void fatal(Object message, Throwable t) { - if(is12) { - getLogger().log(FQCN, (Priority) Level.FATAL, message, t ); - } else { - getLogger().log(FQCN, Level.FATAL, message, t ); - } + getLogger().log(FQCN, Level.FATAL, message, t ); } @@ -244,11 +215,7 @@ public class Log4JLogger implements Log, Serializable { * Check whether the Log4j Logger used is enabled for ERROR priority. */ public boolean isErrorEnabled() { - if(is12) { - return getLogger().isEnabledFor((Priority) Level.ERROR); - } else { - return getLogger().isEnabledFor(Level.ERROR); - } + return getLogger().isEnabledFor(Level.ERROR); } @@ -256,11 +223,7 @@ public class Log4JLogger implements Log, Serializable { * Check whether the Log4j Logger used is enabled for FATAL priority. */ public boolean isFatalEnabled() { - if(is12) { - return getLogger().isEnabledFor((Priority) Level.FATAL); - } else { - return getLogger().isEnabledFor(Level.FATAL); - } + return getLogger().isEnabledFor(Level.FATAL); } @@ -274,20 +237,15 @@ public class Log4JLogger implements Log, Serializable { /** * Check whether the Log4j Logger used is enabled for TRACE priority. - * For Log4J, this returns the value of isDebugEnabled() */ public boolean isTraceEnabled() { - return getLogger().isDebugEnabled(); + return getLogger().isTraceEnabled(); } /** * Check whether the Log4j Logger used is enabled for WARN priority. */ public boolean isWarnEnabled() { - if(is12) { - return getLogger().isEnabledFor((Priority) Level.WARN); - } else { - return getLogger().isEnabledFor(Level.WARN); - } + return getLogger().isEnabledFor(Level.WARN); } } diff --git a/src/java/org/apache/commons/logging/impl/Log4jFactory.java b/src/java/org/apache/commons/logging/impl/Log4jFactory.java deleted file mode 100644 index 016e2cd..0000000 --- a/src/java/org/apache/commons/logging/impl/Log4jFactory.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed 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. - */ - -package org.apache.commons.logging.impl; - - -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Vector; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogConfigurationException; -import org.apache.commons.logging.LogFactory; -import org.apache.log4j.Logger; - -/** - *

Concrete subclass of {@link LogFactory} specific to log4j. - * - * @deprecated Per discussion on COMMONS-DEV, the behind-the-scenes use - * of this class as a proxy factory has been removed. For 1.0, you - * can still request it directly if you wish, but it doesn't really - * do anything useful, and will be removed in 1.1. - * - * @author Costin Manolache - */ -public final class Log4jFactory extends LogFactory { - - public Log4jFactory() { - super(); - } - - /** - * The configuration attributes for this {@link LogFactory}. - */ - private Hashtable attributes = new Hashtable(); - - // Previously returned instances, to avoid creation of proxies - private Hashtable instances = new Hashtable(); - - // --------------------------------------------------------- Public Methods - - /** - * Return the configuration attribute with the specified name (if any), - * or null if there is no such attribute. - * - * @param name Name of the attribute to return - */ - public Object getAttribute(String name) { - return (attributes.get(name)); - } - - - /** - * Return an array containing the names of all currently defined - * configuration attributes. If there are no such attributes, a zero - * length array is returned. - */ - public String[] getAttributeNames() { - Vector names = new Vector(); - Enumeration keys = attributes.keys(); - while (keys.hasMoreElements()) { - names.addElement((String) keys.nextElement()); - } - String results[] = new String[names.size()]; - for (int i = 0; i < results.length; i++) { - results[i] = (String) names.elementAt(i); - } - return (results); - } - - - /** - * Convenience method to derive a name from the specified class and - * call getInstance(String) with it. - * - * @param clazz Class for which a suitable Log name will be derived - * - * @exception LogConfigurationException if a suitable Log - * instance cannot be returned - */ - public Log getInstance(Class clazz) - throws LogConfigurationException - { - Log instance = (Log) instances.get(clazz); - if( instance != null ) - return instance; - - instance=new Log4JLogger( Logger.getLogger( clazz )); - instances.put( clazz, instance ); - return instance; - } - - - public Log getInstance(String name) - throws LogConfigurationException - { - Log instance = (Log) instances.get(name); - if( instance != null ) - return instance; - - instance=new Log4JLogger( Logger.getLogger( name )); - instances.put( name, instance ); - return instance; - } - - - /** - * Release any internal references to previously created {@link Log} - * instances returned by this factory. This is useful in environments - * like servlet containers, which implement application reloading by - * throwing away a ClassLoader. Dangling references to objects in that - * class loader would prevent garbage collection. - */ - public void release() { - - instances.clear(); - - // what's the log4j mechanism to cleanup ??? - } - - - /** - * Remove any configuration attribute associated with the specified name. - * If there is no such attribute, no action is taken. - * - * @param name Name of the attribute to remove - */ - public void removeAttribute(String name) { - attributes.remove(name); - } - - - /** - * Set the configuration attribute with the specified name. Calling - * this with a null value is equivalent to calling - * removeAttribute(name). - * - * @param name Name of the attribute to set - * @param value Value of the attribute to set, or null - * to remove any setting for this attribute - */ - public void setAttribute(String name, Object value) { - if (value == null) { - attributes.remove(name); - } else { - attributes.put(name, value); - } - } - -} diff --git a/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java b/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java index 8a7083d..014bb64 100644 --- a/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java +++ b/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java @@ -149,7 +149,8 @@ public class LogFactoryImpl extends LogFactory { * but broken/unusable for some reason. */ private static final String[] classesToDiscover = { - "org.apache.commons.logging.impl.Log4JLogger", + "org.apache.commons.logging.impl.Log4J13Logger", + "org.apache.commons.logging.impl.Log4J12Logger", "org.apache.commons.logging.impl.Jdk14Logger", "org.apache.commons.logging.impl.Jdk13LumberjackLogger", "org.apache.commons.logging.impl.SimpleLog" diff --git a/src/test/org/apache/commons/logging/log4j/CustomConfigTestCase.java b/src/test/org/apache/commons/logging/log4j/CustomConfigTestCase.java index d50d667..0e1efe6 100644 --- a/src/test/org/apache/commons/logging/log4j/CustomConfigTestCase.java +++ b/src/test/org/apache/commons/logging/log4j/CustomConfigTestCase.java @@ -182,7 +182,7 @@ public class CustomConfigTestCase extends DefaultConfigTestCase { assertNotNull("Log exists", log); assertEquals("Log class", - "org.apache.commons.logging.impl.Log4JLogger", + "org.apache.commons.logging.impl.Log4J12Logger", log.getClass().getName()); // Assert which logging levels have been enabled diff --git a/src/test/org/apache/commons/logging/log4j/DefaultConfigTestCase.java b/src/test/org/apache/commons/logging/log4j/DefaultConfigTestCase.java index 45c9a9b..9e16742 100644 --- a/src/test/org/apache/commons/logging/log4j/DefaultConfigTestCase.java +++ b/src/test/org/apache/commons/logging/log4j/DefaultConfigTestCase.java @@ -154,7 +154,7 @@ public class DefaultConfigTestCase extends TestCase { assertNotNull("Log exists", log); assertEquals("Log class", - "org.apache.commons.logging.impl.Log4JLogger", + "org.apache.commons.logging.impl.Log4J12Logger", log.getClass().getName()); // Can we call level checkers with no exceptions?