commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skitch...@apache.org
Subject svn commit: r382318 - in /jakarta/commons/proper/logging/contrib/simon/jcl2: ./ src/log4j/conf/ src/log4j/java/org/apache/commons/logging/log4j/
Date Thu, 02 Mar 2006 08:24:52 GMT
Author: skitching
Date: Thu Mar  2 00:24:50 2006
New Revision: 382318

URL: http://svn.apache.org/viewcvs?rev=382318&view=rev
Log:
Add Log4J adapter. Rename jarfiles created by build.xml to proper names.

Added:
    jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/conf/
    jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/conf/org.apache.commons.logging.LogHandler
    jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/java/org/apache/commons/logging/log4j/
    jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/java/org/apache/commons/logging/log4j/Log4JLog.java
  (with props)
    jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/java/org/apache/commons/logging/log4j/Log4JLogHandler.java
  (with props)
Modified:
    jakarta/commons/proper/logging/contrib/simon/jcl2/build.xml

Modified: jakarta/commons/proper/logging/contrib/simon/jcl2/build.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/contrib/simon/jcl2/build.xml?rev=382318&r1=382317&r2=382318&view=diff
==============================================================================
--- jakarta/commons/proper/logging/contrib/simon/jcl2/build.xml (original)
+++ jakarta/commons/proper/logging/contrib/simon/jcl2/build.xml Thu Mar  2 00:24:50 2006
@@ -71,10 +71,10 @@
 
 
   <!-- The locations of necessary jar files -->
-  <property name="junit.jar"               value="junit-3.8.1.jar"/>
-  <property name="log4j12.jar"             value="log4j-1.2.12.jar"/>
-  <property name="log4j13.jar"             value="log4j-1.3.0.jar"/>
-  <property name="servletapi.jar"          value="servletapi-2.3.jar"/>
+  <property name="junit.jar"               value="lib/junit-3.8.1.jar"/>
+  <property name="log4j12.jar"             value="lib/log4j-1.2.12.jar"/>
+  <property name="log4j13.jar"             value="lib/log4j-1.3.0.jar"/>
+  <property name="servletapi.jar"          value="lib/servletapi-2.3.jar"/>
 
 
 <!-- ========== Component Declarations ==================================== -->
@@ -153,8 +153,6 @@
     <pathelement location="${build.home}/classes"/>
     <pathelement location="${build.home}/tests"/>
     <pathelement location="${junit.jar}"/>
-    <pathelement location="${logkit.jar}"/>
-    <pathelement location="${avalon-framework.jar}"/>
     <pathelement location="${conf.home}"/>
     <pathelement location="${servletapi.jar}"/>
   </path>
@@ -211,8 +209,6 @@
   <target name="getlibs">
     <mkdir dir="lib"/>
     <get dest="lib/junit-3.8.1.jar" src="${getlibs.base}/junit/jars/junit-3.8.1.jar"/>
-    <get dest="lib/logkit-1.0.1.jar" src="${getlibs.base}/logkit/jars/logkit-1.0.1.jar"/>
-    <get dest="lib/avalon-framework-4.1.3.jar" src="${getlibs.base}/avalon-framework/jars/avalon-framework-4.1.3.jar"/>
     <get dest="lib/log4j-1.2.12.jar" src="${getlibs.base}/log4j/jars/log4j-1.2.12.jar"/>
     <get dest="lib/servletapi-2.3.jar" src="${getlibs.base}/servletapi/jars/servletapi-2.3.jar"/>
   </target>
@@ -248,7 +244,7 @@
           description="Compile shareable components"/>
 
   <target name="compile-only" 
-    depends="prepare,compile-core,compile-core-static,compile-noop,compile-simple"/>
+    depends="prepare,compile-core,compile-core-static,compile-noop,compile-simple,compile-log4j"/>
 
   <target name="compile-core" depends="prepare">
   	<mkdir dir="src/core/classes"/>
@@ -284,7 +280,7 @@
         <pathelement location="src/core/classes"/>
       </classpath>
     </javac>
-    <jar jarfile="src/core-static/core-static.jar"
+    <jar jarfile="src/core-static/commons-logging-core-static.jar"
          manifest="${build.home}/conf/MANIFEST.MF">
       <fileset dir="src/core-static/classes">
         <include name="org/apache/commons/logging/**" />
@@ -321,7 +317,7 @@
       </classpath>
         </javac>
 
-  	<jar jarfile="src/noop/noop.jar"
+  	<jar jarfile="src/noop/commons-logging-noop.jar"
          basedir="src/noop/classes"
          manifest="${build.home}/conf/MANIFEST.MF">
         <include name="org/apache/commons/logging/**" />
@@ -350,7 +346,7 @@
 	        <pathelement location="src/core/classes"/>
 	      </classpath>
 	    </javac>
-        <jar jarfile="src/simple/simple.jar"
+        <jar jarfile="src/simple/commons-logging-simple.jar"
              basedir="src/simple/classes"
              manifest="${build.home}/conf/MANIFEST.MF">
           <include name="org/apache/commons/logging/**" />
@@ -359,15 +355,46 @@
         </jar>
 	  </target>
 
+	  <target name="compile-log4j" depends="prepare, compile-core">
+	  	<mkdir dir="src/log4j/classes"/>
+	  	<mkdir dir="src/log4j/classes/META-INF"/>
+	  	<mkdir dir="src/log4j/classes/META-INF/services"/>
+	  	<copy file="src/log4j/conf/org.apache.commons.logging.LogHandler"
+	  		todir="src/log4j/classes/META-INF/services"/>
+	    <javac srcdir="src/log4j/java"
+	           destdir="src/log4j/classes"
+	           debug="${compile.debug}"
+	           deprecation="${compile.deprecation}"
+	           optimize="${compile.optimize}"
+	           source="${source.version}"
+	           target="${target.version}">
+
+	      <classpath refid="compile.classpath"/>
+	      <classpath>
+	        <pathelement location="src/core/classes"/>
+	        <pathelement location="${log4j12.jar}"/>
+	      </classpath>
+	    </javac>
+      <jar jarfile="src/log4j/commons-logging-log4j.jar"
+           basedir="src/log4j/classes"
+           manifest="${build.home}/conf/MANIFEST.MF">
+        <include name="org/apache/commons/logging/**" />
+        <include name="META-INF/**"/>
+        <exclude name="**/package.html"/>
+      </jar>
+	  </target>
+
   <target name="clean" description="Clean build and distribution directories">
     <mkdir dir='${build.home}'/>
     <delete dir="src/core/classes"/>
     <delete dir="src/core-static/classes"/>
-    <delete file="src/core-static/core-static.jar"/>
+    <delete file="src/core-static/commons-logging-core-static.jar"/>
     <delete dir="src/noop/classes"/>
-    <delete file="src/noop/noop.jar"/>
+    <delete file="src/noop/commons-logging-noop.jar"/>
     <delete dir="src/simple/classes"/>
-    <delete file="src/simple/simple.jar"/>
+    <delete file="src/simple/commons-logging-simple.jar"/>
+    <delete dir="src/log4j/classes"/>
+    <delete file="src/log4j/commons-logging-log4j.jar"/>
   </target>
 
 </project>

Added: jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/conf/org.apache.commons.logging.LogHandler
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/conf/org.apache.commons.logging.LogHandler?rev=382318&view=auto
==============================================================================
--- jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/conf/org.apache.commons.logging.LogHandler
(added)
+++ jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/conf/org.apache.commons.logging.LogHandler
Thu Mar  2 00:24:50 2006
@@ -0,0 +1 @@
+org.apache.commons.logging.log4j.Log4JLogHandler

Added: jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/java/org/apache/commons/logging/log4j/Log4JLog.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/java/org/apache/commons/logging/log4j/Log4JLog.java?rev=382318&view=auto
==============================================================================
--- jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/java/org/apache/commons/logging/log4j/Log4JLog.java
(added)
+++ jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/java/org/apache/commons/logging/log4j/Log4JLog.java
Thu Mar  2 00:24:50 2006
@@ -0,0 +1,285 @@
+/*
+ * Copyright 2001-2006 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.log4j;
+
+import java.io.Serializable;
+import org.apache.commons.logging.Log;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+
+/**
+ * Maps calls onto an underlying Log4J Logger object.
+ */
+public class Log4JLog implements Log, Serializable {
+
+    // ------------------------------------------------------------- Attributes
+
+    /** The fully qualified name of this Log4JLog class. */
+    private static final String FQCN = Log4JLog.class.getName();
+    
+    /**
+     * Member used to support TRACE levels for versions of log4j that
+     * implement it.
+     * <p>
+     * When running on a version of Log4J that supports Priority.TRACE,
+     * this equals Priority.TRACE. Otherwise this equals Priority.DEBUG.
+     */
+    private static Priority traceLevel;
+    
+    /** Log to this underlying logger */
+    private transient Logger logger;
+
+    /** Logger name */
+    private String name;
+
+    // ------------------------------------------------------------
+    // 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;
+        }
+    }
+
+    // ------------------------------------------------------------ Constructor
+
+    /**
+     * Base constructor.
+     */
+    public Log4JLog(String name) {
+        this.name = name;
+        
+        // Call Log4J to retrieve appropriate underlying Logger object
+        this.logger = Logger.getLogger(name);
+    }
+
+    // --------------------------------------------------------- 
+    // 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>.
+     * When using a log4j version that does not support the <code>TRACE</code>
+     * level, the message will be logged at the <code>DEBUG</code> level.
+     *
+     * @param message to log
+     * @see org.apache.commons.logging.Log#trace(Object)
+     */
+    public void trace(Object message) {
+        logger.log(FQCN, traceLevel, message, null );
+    }
+
+    /**
+     * Logs a message with <code>org.apache.log4j.Priority.TRACE</code>.
+     * When using a log4j version that does not support the <code>TRACE</code>
+     * level, the message will be logged at the <code>DEBUG</code> level.
+     *
+     * @param message to log
+     * @param t log this cause
+     * @see org.apache.commons.logging.Log#trace(Object, Throwable)
+     */
+    public void trace(Object message, Throwable t) {
+        logger.log(FQCN, traceLevel, message, t );
+    }
+
+    /**
+     * Logs a message with <code>org.apache.log4j.Priority.DEBUG</code>.
+     *
+     * @param message to log
+     * @see org.apache.commons.logging.Log#debug(Object)
+     */
+    public void debug(Object message) {
+        logger.log(FQCN, Priority.DEBUG, message, null );
+    }
+
+    /**
+     * Logs a message with <code>org.apache.log4j.Priority.DEBUG</code>.
+     *
+     * @param message to log
+     * @param t log this cause
+     * @see org.apache.commons.logging.Log#debug(Object, Throwable)
+     */
+    public void debug(Object message, Throwable t) {
+        logger.log(FQCN, Priority.DEBUG, message, t );
+    }
+
+    /**
+     * Logs a message with <code>org.apache.log4j.Priority.INFO</code>.
+     *
+     * @param message to log
+     * @see org.apache.commons.logging.Log#info(Object)
+     */
+    public void info(Object message) {
+        logger.log(FQCN, Priority.INFO, message, null );
+    }
+
+    /**
+     * Logs a message with <code>org.apache.log4j.Priority.INFO</code>.
+     *
+     * @param message to log
+     * @param t log this cause
+     * @see org.apache.commons.logging.Log#info(Object, Throwable)
+     */
+    public void info(Object message, Throwable t) {
+        logger.log(FQCN, Priority.INFO, message, t );
+    }
+
+    /**
+     * Logs a message with <code>org.apache.log4j.Priority.WARN</code>.
+     *
+     * @param message to log
+     * @see org.apache.commons.logging.Log#warn(Object)
+     */
+    public void warn(Object message) {
+        logger.log(FQCN, Priority.WARN, message, null );
+    }
+
+    /**
+     * Logs a message with <code>org.apache.log4j.Priority.WARN</code>.
+     *
+     * @param message to log
+     * @param t log this cause
+     * @see org.apache.commons.logging.Log#warn(Object, Throwable)
+     */
+    public void warn(Object message, Throwable t) {
+        logger.log(FQCN, Priority.WARN, message, t );
+    }
+
+    /**
+     * Logs a message with <code>org.apache.log4j.Priority.ERROR</code>.
+     *
+     * @param message to log
+     * @see org.apache.commons.logging.Log#error(Object)
+     */
+    public void error(Object message) {
+        logger.log(FQCN, Priority.ERROR, message, null );
+    }
+
+    /**
+     * Logs a message with <code>org.apache.log4j.Priority.ERROR</code>.
+     *
+     * @param message to log
+     * @param t log this cause
+     * @see org.apache.commons.logging.Log#error(Object, Throwable)
+     */
+    public void error(Object message, Throwable t) {
+        logger.log(FQCN, Priority.ERROR, message, t );
+    }
+
+    /**
+     * Logs a message with <code>org.apache.log4j.Priority.FATAL</code>.
+     *
+     * @param message to log
+     * @see org.apache.commons.logging.Log#fatal(Object)
+     */
+    public void fatal(Object message) {
+        logger.log(FQCN, Priority.FATAL, message, null );
+    }
+
+    /**
+     * Logs a message with <code>org.apache.log4j.Priority.FATAL</code>.
+     *
+     * @param message to log
+     * @param t log this cause
+     * @see org.apache.commons.logging.Log#fatal(Object, Throwable)
+     */
+    public void fatal(Object message, Throwable t) {
+        logger.log(FQCN, Priority.FATAL, message, t );
+    }
+
+    /**
+     * Check whether the Log4j Logger used is enabled for <code>TRACE</code>
priority.
+     * When using a log4j version that does not support the TRACE level, this call
+     * will report whether <code>DEBUG</code> is enabled or not.
+     */
+    public boolean isTraceEnabled() {
+        return logger.isEnabledFor(traceLevel);
+    }
+
+    /**
+     * Check whether the Log4j Logger used is enabled for <code>DEBUG</code>
priority.
+     */
+    public boolean isDebugEnabled() {
+        return logger.isDebugEnabled();
+    }
+
+    /**
+     * Check whether the Log4j Logger used is enabled for <code>INFO</code> priority.
+     */
+    public boolean isInfoEnabled() {
+        return logger.isInfoEnabled();
+    }
+
+    /**
+     * Check whether the Log4j Logger used is enabled for <code>WARN</code> priority.
+     */
+    public boolean isWarnEnabled() {
+        return logger.isEnabledFor(Priority.WARN);
+    }
+
+    /**
+     * Check whether the Log4j Logger used is enabled for <code>ERROR</code>
priority.
+     */
+    public boolean isErrorEnabled() {
+        return logger.isEnabledFor(Priority.ERROR);
+    }
+
+    /**
+     * Check whether the Log4j Logger used is enabled for <code>FATAL</code>
priority.
+     */
+    public boolean isFatalEnabled() {
+        return logger.isEnabledFor(Priority.FATAL);
+    }
+}

Propchange: jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/java/org/apache/commons/logging/log4j/Log4JLog.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/java/org/apache/commons/logging/log4j/Log4JLog.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/java/org/apache/commons/logging/log4j/Log4JLogHandler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/java/org/apache/commons/logging/log4j/Log4JLogHandler.java?rev=382318&view=auto
==============================================================================
--- jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/java/org/apache/commons/logging/log4j/Log4JLogHandler.java
(added)
+++ jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/java/org/apache/commons/logging/log4j/Log4JLogHandler.java
Thu Mar  2 00:24:50 2006
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2006 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.log4j;
+
+import java.util.HashMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogHandler;
+
+/**
+ * Manufactures Log4JLog instances.
+ */
+
+public final class Log4JLogHandler implements LogHandler {
+    /**
+     * The fact that we use a HashMap here implies that this class won't
+     * run on 1.1 JVMs. However as Log4J doesn't support it, that isn't
+     * a problem.
+     */
+    private HashMap logs = new HashMap();
+    
+    public Log getLog(Class clazz) {
+        return getLog(clazz.getName());
+    }
+
+    public synchronized Log getLog(String category) {
+        Log log = (Log) logs.get(category);
+        if (log == null) {
+            log = new Log4JLog(category);
+            logs.put(category, log);
+        }
+        return log;
+    }
+
+    public synchronized void release() {
+        logs.clear();
+    }
+}
\ No newline at end of file

Propchange: jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/java/org/apache/commons/logging/log4j/Log4JLogHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/logging/contrib/simon/jcl2/src/log4j/java/org/apache/commons/logging/log4j/Log4JLogHandler.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message