[jboss-cvs] apache/commons-logging/src/java/org/apache/commons/logging/impl ...
Scott Stark
scott.stark at jboss.com
Sun Feb 11 15:23:47 EST 2007
User: starksm
Date: 07/02/11 15:23:47
Modified: commons-logging/src/java/org/apache/commons/logging/impl
Tag: JBoss_Apache_Common_Logging_Branch_1_1
Log4jProxy.java Log4JLogger.java
Log:
Update for changes in expected discovery behavior
Revision Changes Path
No revision
No revision
1.3.6.2 +17 -6 apache/commons-logging/src/java/org/apache/commons/logging/impl/Log4jProxy.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Log4jProxy.java
===================================================================
RCS file: /cvsroot/jboss/apache/commons-logging/src/java/org/apache/commons/logging/impl/Log4jProxy.java,v
retrieving revision 1.3.6.1
retrieving revision 1.3.6.2
diff -u -b -r1.3.6.1 -r1.3.6.2
--- Log4jProxy.java 9 Feb 2007 07:47:30 -0000 1.3.6.1
+++ Log4jProxy.java 11 Feb 2007 20:23:47 -0000 1.3.6.2
@@ -33,7 +33,7 @@
* using the current thread context class loader.
*
* @author Scott.Stark at jboss.org
- * @version $Revision: 1.3.6.1 $
+ * @version $Revision: 1.3.6.2 $
*/
public class Log4jProxy implements Log, Serializable
{
@@ -116,12 +116,23 @@
TRACE = DEBUG;
try
{
+ // 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
+ {
+ TRACE = levelClass.getDeclaredField("TRACE").get(null);
+ }
+ catch(Exception ex)
+ {
+ // Try to load the jboss org.jboss.logging.XLevel
levelClass = tcl.loadClass("org.jboss.logging.XLevel");
Class[] toLevelSig = {String.class, DEBUG.getClass()};
toLevel = levelClass.getMethod("toLevel", toLevelSig);
Object[] args = {"TRACE", DEBUG};
TRACE = toLevel.invoke(null, args);
}
+ }
catch(Throwable ignore)
{
// Default to DEBUG
1.3.4.1 +52 -99 apache/commons-logging/src/java/org/apache/commons/logging/impl/Log4JLogger.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Log4JLogger.java
===================================================================
RCS file: /cvsroot/jboss/apache/commons-logging/src/java/org/apache/commons/logging/impl/Log4JLogger.java,v
retrieving revision 1.3
retrieving revision 1.3.4.1
diff -u -b -r1.3 -r1.3.4.1
--- Log4JLogger.java 9 Feb 2007 06:57:15 -0000 1.3
+++ Log4JLogger.java 11 Feb 2007 20:23:47 -0000 1.3.4.1
@@ -19,9 +19,6 @@
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
@@ -40,99 +37,57 @@
* a non-binary-compatible change. The class generated by compiling this code against
* log4j 1.2 will therefore not run against log4j 1.3.
*
+ * Implementation of Log that reflectively maps to a log4j
+ *
* @author <a href="mailto:sanders at apache.org">Scott Sanders</a>
* @author Rod Waldhoff
* @author Robert Burrell Donkin
- * @version $Id: Log4JLogger.java,v 1.3 2007/02/09 06:57:15 starksm Exp $
+ * @author Scott.Stark at jboss.org
+ * @version $Id: Log4JLogger.java,v 1.3.4.1 2007/02/11 20:23:47 starksm Exp $
*/
public class Log4JLogger implements Log, Serializable {
+ private static final long serialVersionUID = 1;
// ------------------------------------------------------------- Attributes
- /** The fully qualified name of the Log4JLogger class. */
- private static final String FQCN = Log4JLogger.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) Level.class.getDeclaredField("TRACE").get(null);
- } catch(Exception ex) {
- // ok, trace not available
- traceLevel = Priority.DEBUG;
- }
- }
-
+ private transient Log theLogger;
// ------------------------------------------------------------ Constructor
public Log4JLogger() {
+ this(null);
}
/**
* Base constructor.
*/
- public Log4JLogger(String name) {
+ public Log4JLogger(String name)
+ {
this.name = name;
- this.logger = getLogger();
- }
-
- /** For use with a log4j factory.
+ /* Conform to the expectation that ExceptionInInitializerError is
+ thrown if log4j is not visible
*/
- public Log4JLogger(Logger logger ) {
- this.name = logger.getName();
- this.logger=logger;
+ try
+ {
+ ClassLoader loader = Log4jProxy.threadContextClassLoader();
+ Class priorityClass = Class.forName("org.apache.log4j.Priority", false, loader);
+ Class levelClass = Class.forName("org.apache.log4j.Level", false, loader);
+ if (!priorityClass.isAssignableFrom(levelClass))
+ {
+ // nope, this is log4j 1.3, so force an ExceptionInInitializerError
+ throw new InstantiationError("Log4J 1.2 not available");
+ }
+ }
+ catch(Throwable e)
+ {
+ throw new ExceptionInInitializerError(e);
+ }
}
-
-
- // ---------------------------------------------------------
- // 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.
- // ---------------------------------------------------------
-
/**
* Logs a message with <code>org.apache.log4j.Priority.TRACE</code>.
@@ -143,7 +98,7 @@
* @see org.apache.commons.logging.Log#trace(Object)
*/
public void trace(Object message) {
- getLogger().log(FQCN, traceLevel, message, null );
+ getLogger().trace(message);
}
@@ -157,7 +112,7 @@
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
*/
public void trace(Object message, Throwable t) {
- getLogger().log(FQCN, traceLevel, message, t );
+ getLogger().trace(message, t );
}
@@ -168,7 +123,7 @@
* @see org.apache.commons.logging.Log#debug(Object)
*/
public void debug(Object message) {
- getLogger().log(FQCN, Priority.DEBUG, message, null );
+ getLogger().debug(message, null );
}
/**
@@ -179,7 +134,7 @@
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
*/
public void debug(Object message, Throwable t) {
- getLogger().log(FQCN, Priority.DEBUG, message, t );
+ getLogger().debug(message, t );
}
@@ -190,7 +145,7 @@
* @see org.apache.commons.logging.Log#info(Object)
*/
public void info(Object message) {
- getLogger().log(FQCN, Priority.INFO, message, null );
+ getLogger().info(message, null );
}
@@ -202,7 +157,7 @@
* @see org.apache.commons.logging.Log#info(Object, Throwable)
*/
public void info(Object message, Throwable t) {
- getLogger().log(FQCN, Priority.INFO, message, t );
+ getLogger().info(message, t );
}
@@ -213,7 +168,7 @@
* @see org.apache.commons.logging.Log#warn(Object)
*/
public void warn(Object message) {
- getLogger().log(FQCN, Priority.WARN, message, null );
+ getLogger().warn(message, null );
}
@@ -225,7 +180,7 @@
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
*/
public void warn(Object message, Throwable t) {
- getLogger().log(FQCN, Priority.WARN, message, t );
+ getLogger().warn(message, t );
}
@@ -236,7 +191,7 @@
* @see org.apache.commons.logging.Log#error(Object)
*/
public void error(Object message) {
- getLogger().log(FQCN, Priority.ERROR, message, null );
+ getLogger().error(message, null );
}
@@ -248,7 +203,7 @@
* @see org.apache.commons.logging.Log#error(Object, Throwable)
*/
public void error(Object message, Throwable t) {
- getLogger().log(FQCN, Priority.ERROR, message, t );
+ getLogger().error(message, t );
}
@@ -259,7 +214,7 @@
* @see org.apache.commons.logging.Log#fatal(Object)
*/
public void fatal(Object message) {
- getLogger().log(FQCN, Priority.FATAL, message, null );
+ getLogger().fatal(message, null );
}
@@ -271,18 +226,7 @@
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
*/
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);
+ getLogger().fatal(message, t );
}
@@ -298,7 +242,7 @@
* Check whether the Log4j Logger used is enabled for <code>ERROR</code> priority.
*/
public boolean isErrorEnabled() {
- return getLogger().isEnabledFor(Priority.ERROR);
+ return getLogger().isErrorEnabled();
}
@@ -306,7 +250,7 @@
* Check whether the Log4j Logger used is enabled for <code>FATAL</code> priority.
*/
public boolean isFatalEnabled() {
- return getLogger().isEnabledFor(Priority.FATAL);
+ return getLogger().isFatalEnabled();
}
@@ -324,13 +268,22 @@
* will report whether <code>DEBUG</code> is enabled or not.
*/
public boolean isTraceEnabled() {
- return getLogger().isEnabledFor(traceLevel);
+ return getLogger().isTraceEnabled();
}
/**
* Check whether the Log4j Logger used is enabled for <code>WARN</code> priority.
*/
public boolean isWarnEnabled() {
- return getLogger().isEnabledFor(Priority.WARN);
+ return getLogger().isWarnEnabled();
+ }
+
+ /**
+ * Return the native Logger instance we are using.
+ */
+ Log getLogger() {
+ if( theLogger == null )
+ this.theLogger = new Log4jProxy(name);
+ return (this.theLogger);
}
}
More information about the jboss-cvs-commits
mailing list