[logback-dev] svn commit: r1078 - in logback/trunk: . log4j-bridge log4j-bridge/src log4j-bridge/src/main log4j-bridge/src/main/java log4j-bridge/src/main/java/org log4j-bridge/src/main/java/org/apache log4j-bridge/src/main/java/org/apache/log4j log4j-bridge/src/test log4j-bridge/src/test/java log4j-bridge/src/test/java/org log4j-bridge/src/test/java/org/apache log4j-bridge/src/test/java/org/apache/log4j logback-classic/src/main/java/ch/qos/logback/classic

noreply.seb at qos.ch noreply.seb at qos.ch
Wed Dec 13 14:27:05 CET 2006


Author: seb
Date: Wed Dec 13 14:27:05 2006
New Revision: 1078

Added:
   logback/trunk/log4j-bridge/   (props changed)
   logback/trunk/log4j-bridge/pom.xml
   logback/trunk/log4j-bridge/src/
   logback/trunk/log4j-bridge/src/main/
   logback/trunk/log4j-bridge/src/main/java/
   logback/trunk/log4j-bridge/src/main/java/org/
   logback/trunk/log4j-bridge/src/main/java/org/apache/
   logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/
   logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Category.java
   logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Level.java
   logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Log4jLoggerFactory.java
   logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Logger.java
   logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Priority.java
   logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/package.html
   logback/trunk/log4j-bridge/src/test/
   logback/trunk/log4j-bridge/src/test/java/
   logback/trunk/log4j-bridge/src/test/java/org/
   logback/trunk/log4j-bridge/src/test/java/org/apache/
   logback/trunk/log4j-bridge/src/test/java/org/apache/log4j/
   logback/trunk/log4j-bridge/src/test/java/org/apache/log4j/InvokeLog4jTest.java
Modified:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java
   logback/trunk/pom.xml

Log:
Added a log4j bridge module

Added: logback/trunk/log4j-bridge/pom.xml
==============================================================================
--- (empty file)
+++ logback/trunk/log4j-bridge/pom.xml	Wed Dec 13 14:27:05 2006
@@ -0,0 +1,40 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+	<parent>
+		<groupId>ch.qos.logback</groupId>
+		<artifactId>logback-parent</artifactId>
+		<version>0.7-SNAPSHOT</version>
+	</parent>
+	
+	<modelVersion>4.0.0</modelVersion>
+
+	<groupId>ch.qos.logback</groupId>
+	<artifactId>log4j-bridge</artifactId>
+	<version>0.7-SNAPSHOT</version>
+	<packaging>jar</packaging>
+	<name>Log4j Bridge Module</name>
+
+	<url>http://logback.qos.ch</url>
+	<description>
+		<!-- 
+			Never _never_ let Eclipse's auto format function add
+			a line return in the description.
+			The generated jar will contain a corrupt MANIFEST file.
+		-->
+		Logback: the generic, reliable, fast and flexible logging library for Java.
+	</description>
+	<licenses>
+		<license>
+			<name>Apache Software Licenses</name>
+      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>			
+		</license>
+	</licenses>
+
+	<dependencies>
+		<dependency>
+			<groupId>ch.qos.logback</groupId>
+			<artifactId>logback-classic</artifactId>
+		</dependency>
+	</dependencies>
+
+</project>
\ No newline at end of file

Added: logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Category.java
==============================================================================
--- (empty file)
+++ logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Category.java	Wed Dec 13 14:27:05 2006
@@ -0,0 +1,242 @@
+/*
+ * 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.log4j;
+
+import org.slf4j.LoggerFactory;
+import org.slf4j.Marker;
+import org.slf4j.MarkerFactory;
+
+/**
+ * <p>
+ * This class is a minimal implementation of the origianl
+ * org.apache.log4j.Logger class delegating all calls to a
+ * {@link org.slf4j.Logger} instance, which in turn will delegate to a final
+ * logging system chosen by the user..
+ * </p>
+ * 
+ * <p>
+ * Log4j's <code>debug()</code>, <code>info()</code>, <code>warn()</code>,
+ * <code>error()</code> printing methods are directly mapped to their SLF4J
+ * equivalents. Log4j's <code>trace()</code> printing method is mapped to
+ * SLF4J's <code>debug()</code> method with a TRACE marker. Log4j's
+ * <code>fatal()</code> printing method is mapped to SLF4J's
+ * <code>error()</code> method with a FATAL marker.
+ * 
+ * @author S&eacute;bastien Pennec
+ * @author Ceki G&uuml;lc&uuml;
+ */
+
+public class Category {
+
+  private String name;
+
+  private ch.qos.logback.classic.Logger lbLogger;
+
+  private static Marker TRACE_MARKER = MarkerFactory.getMarker("TRACE");
+  private static Marker FATAL_MARKER = MarkerFactory.getMarker("FATAL");
+
+  Category(String name) {
+    this.name = name;
+    lbLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(name);
+  }
+
+  public static Logger getLogger(String name) {
+    return Log4jLoggerFactory.getLogger(name);
+  }
+
+  public static Logger getLogger(Class clazz) {
+    return getLogger(clazz.getName());
+  }
+
+  /**
+   * Does the obvious.
+   * 
+   * @return
+   */
+  public static Logger getRootLogger() {
+    return getLogger("root");
+  }
+
+  /**
+   * Returns the obvious.
+   * 
+   * @return
+   */
+  public String getName() {
+    return name;
+  }
+
+  /**
+   * Delegates to {@link org.slf4j.Logger#isDebugEnabled} method of the SLF4J
+   * API, in addition, the call is marked with a marker named "TRACE".
+   */
+  public boolean isTraceEnabled() {
+    return lbLogger.isDebugEnabled(TRACE_MARKER);
+  }
+
+  /**
+   * Delegates to {@link org.slf4j.Logger#isDebugEnabled} method of the SLF4J
+   * API.
+   */
+  public boolean isDebugEnabled() {
+    return lbLogger.isDebugEnabled();
+  }
+
+  /**
+   * Delegates to {@link org.slf4j.Logger#isInfoEnabled} method of the SLF4J
+   * API.
+   */
+  public boolean isInfoEnabled() {
+    return lbLogger.isInfoEnabled();
+  }
+
+  /**
+   * Delegates to {@link org.slf4j.Logger#isWarnEnabled} method of the SLF4J
+   * API.
+   */
+  public boolean isWarnEnabled() {
+    return lbLogger.isWarnEnabled();
+  }
+
+  /**
+   * Delegates to {@link org.slf4j.Logger#isErrorEnabled} method of the SLF4J
+   * API.
+   */
+  public boolean isErrorEnabled() {
+    return lbLogger.isErrorEnabled();
+  }
+
+  /**
+   * Delegates to {@link org.slf4j.Logger#debug(String)} method of the SLF4J
+   * API, in addition, the call is marked with a marker named "TRACE".
+   */
+  public void trace(Object message) {
+    lbLogger.debug(TRACE_MARKER, (String) message);
+  }
+
+  /**
+   * Delegates to {@link org.slf4j.Logger#debug(String,Throwable)} method of the
+   * SLF4J API, in addition, the call is marked with a marker named "TRACE".
+   */
+  public void trace(Object message, Throwable t) {
+    lbLogger.debug(TRACE_MARKER, (String) message, t);
+  }
+
+  /**
+   * Delegates to {@link org.slf4j.Logger#debug(String)} method of the SLF4J
+   * API.
+   */
+  public void debug(Object message) {
+    // casting to String as SLF4J only accepts String instances, not Object
+    // instances.
+    lbLogger.debug((String) message);
+  }
+
+  /**
+   * Delegates to {@link org.slf4j.Logger#debug(String,Throwable)} method of the
+   * SLF4J API.
+   */
+  public void debug(Object message, Throwable t) {
+    lbLogger.debug((String) message, t);
+  }
+
+  /**
+   * Delegates to {@link org.slf4j.Logger#info(String)} method of the SLF4J API.
+   */
+  public void info(Object message) {
+    lbLogger.info((String) message);
+  }
+
+  /**
+   * Delegates to {@link org.slf4j.Logger#info(String, Throwable)} method of the
+   * SLF4J API.
+   */
+  public void info(Object message, Throwable t) {
+    lbLogger.info((String) message, t);
+  }
+
+  /**
+   * Delegates to {@link org.slf4j.Logger#warn(String)} method of the SLF4J API.
+   */
+  public void warn(Object message) {
+    lbLogger.warn((String) message);
+  }
+
+  /**
+   * Delegates to {@link org.slf4j.Logger#warn(String,Throwable)} method of the
+   * SLF4J API.
+   */
+  public void warn(Object message, Throwable t) {
+    lbLogger.warn((String) message, t);
+  }
+
+  /**
+   * Delegates to {@link org.slf4j.Logger#error(String)} method of the SLF4J
+   * API.
+   */
+  public void error(Object message) {
+    lbLogger.error((String) message);
+  }
+
+  /**
+   * Delegates to {@link org.slf4j.Logger#error(String,Throwable)} method of the
+   * SLF4J API.
+   */
+  public void error(Object message, Throwable t) {
+    lbLogger.error((String) message, t);
+  }
+
+  /**
+   * Delegates to {@link org.slf4j.Logger#error(String)} method of the SLF4J
+   * API, in addition, the call is marked with a marker named "FATAL".
+   */
+  public void fatal(Object message) {
+    lbLogger.error(FATAL_MARKER, (String) message);
+  }
+
+  /**
+   * Delegates to {@link org.slf4j.Logger#error(String,Throwable)} method of the
+   * SLF4J API, in addition, the call is marked with a marker named "FATAL".
+   */
+  public void fatal(Object message, Throwable t) {
+    lbLogger.error(FATAL_MARKER, (String) message, t);
+  }
+
+  public void log(String FQCN, Priority p, Object msg, Throwable t) {
+    ch.qos.logback.classic.Level level;
+    switch (p.level) {
+    case Priority.DEBUG_INT:
+      level = ch.qos.logback.classic.Level.DEBUG;
+      break;
+    case Priority.INFO_INT:
+      level = ch.qos.logback.classic.Level.INFO;
+      break;
+    case Priority.WARN_INT:
+      level = ch.qos.logback.classic.Level.WARN;
+      break;
+    case Priority.ERROR_INT:
+      level = ch.qos.logback.classic.Level.ERROR;
+      break;
+    case Priority.FATAL_INT:
+      level = ch.qos.logback.classic.Level.ERROR;
+      break;
+    default:
+      throw new IllegalStateException("Unknown Priority " + p);
+    }
+    lbLogger.filterAndLog(FQCN, null, level, msg.toString(), null, t);
+  }
+
+}

Added: logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Level.java
==============================================================================
--- (empty file)
+++ logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Level.java	Wed Dec 13 14:27:05 2006
@@ -0,0 +1,218 @@
+/*
+ * Copyright 1999-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.
+ * 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.
+ */
+
+// Contributors:  Kitching Simon <Simon.Kitching at orange.ch>
+//                Nicholas Wolff
+
+package org.apache.log4j;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+
+/**
+   Defines the minimum set of levels recognized by the system, that is
+   <code>OFF</code>, <code>FATAL</code>, <code>ERROR</code>,
+   <code>WARN</code>, <code>INFO</code, <code>DEBUG</code> and
+   <code>ALL</code>.
+
+   <p>The <code>Level</code> class may be subclassed to define a larger
+   level set.
+
+   @author Ceki G&uuml;lc&uuml;
+
+ */
+public class Level extends Priority implements Serializable {
+
+   /**
+    * TRACE level integer value.
+    * @since 1.2.12
+    */
+  public static final int TRACE_INT = 5000;
+
+  /**
+     The <code>OFF</code> has the highest possible rank and is
+     intended to turn off logging.  */
+  final static public Level OFF = new Level(OFF_INT, "OFF", 0);
+
+  /**
+     The <code>FATAL</code> level designates very severe error
+     events that will presumably lead the application to abort.
+   */
+  final static public Level FATAL = new Level(FATAL_INT, "FATAL", 0);
+
+  /**
+     The <code>ERROR</code> level designates error events that
+     might still allow the application to continue running.  */
+  final static public Level ERROR = new Level(ERROR_INT, "ERROR", 3);
+
+  /**
+     The <code>WARN</code> level designates potentially harmful situations.
+  */
+  final static public Level WARN  = new Level(WARN_INT, "WARN",  4);
+
+  /**
+     The <code>INFO</code> level designates informational messages
+     that highlight the progress of the application at coarse-grained
+     level.  */
+  final static public Level INFO  = new Level(INFO_INT, "INFO",  6);
+
+  /**
+     The <code>DEBUG</code> Level designates fine-grained
+     informational events that are most useful to debug an
+     application.  */
+  final static public Level DEBUG = new Level(DEBUG_INT, "DEBUG", 7);
+
+  /**
+    * The <code>TRACE</code> Level designates finer-grained
+    * informational events than the <code>DEBUG</code level.
+   *  @since 1.2.12
+    */
+  public static final Level TRACE = new Level(TRACE_INT, "TRACE", 7);
+
+
+  /**
+     The <code>ALL</code> has the lowest possible rank and is intended to
+     turn on all logging.  */
+  final static public Level ALL = new Level(ALL_INT, "ALL", 7);
+
+  /**
+   * Serialization version id.
+   */
+  static final long serialVersionUID = 3491141966387921974L;
+
+  /**
+     Instantiate a Level object.
+   */
+  protected
+  Level(int level, String levelStr, int syslogEquivalent) {
+    super(level, levelStr, syslogEquivalent);
+  }
+
+
+  /**
+     Convert the string passed as argument to a level. If the
+     conversion fails, then this method returns {@link #DEBUG}. 
+  */
+  public
+  static
+  Level toLevel(String sArg) {
+    return (Level) toLevel(sArg, Level.DEBUG);
+  }
+
+  /**
+    Convert an integer passed as argument to a level. If the
+    conversion fails, then this method returns {@link #DEBUG}.
+
+  */
+  public
+  static
+  Level toLevel(int val) {
+    return (Level) toLevel(val, Level.DEBUG);
+  }
+
+  /**
+    Convert an integer passed as argument to a level. If the
+    conversion fails, then this method returns the specified default.
+  */
+  public
+  static
+  Level toLevel(int val, Level defaultLevel) {
+    switch(val) {
+    case ALL_INT: return ALL;
+    case DEBUG_INT: return Level.DEBUG;
+    case INFO_INT: return Level.INFO;
+    case WARN_INT: return Level.WARN;
+    case ERROR_INT: return Level.ERROR;
+    case FATAL_INT: return Level.FATAL;
+    case OFF_INT: return OFF;
+    case TRACE_INT: return Level.TRACE;
+    default: return defaultLevel;
+    }
+  }
+
+  /**
+     Convert the string passed as argument to a level. If the
+     conversion fails, then this method returns the value of
+     <code>defaultLevel</code>.  
+  */
+  public
+  static
+  Level toLevel(String sArg, Level defaultLevel) {                  
+    if(sArg == null)
+       return defaultLevel;
+    
+    String s = sArg.toUpperCase();
+
+    if(s.equals("ALL")) return Level.ALL; 
+    if(s.equals("DEBUG")) return Level.DEBUG; 
+    if(s.equals("INFO"))  return Level.INFO;
+    if(s.equals("WARN"))  return Level.WARN;  
+    if(s.equals("ERROR")) return Level.ERROR;
+    if(s.equals("FATAL")) return Level.FATAL;
+    if(s.equals("OFF")) return Level.OFF;
+    if(s.equals("TRACE")) return Level.TRACE;
+    return defaultLevel;
+  }
+
+    /**
+     * Custom deserialization of Level.
+     * @param s serialization stream.
+     * @throws IOException if IO exception.
+     * @throws ClassNotFoundException if class not found.
+     */
+    private void readObject(final ObjectInputStream s) throws IOException, ClassNotFoundException {
+      s.defaultReadObject();
+      level = s.readInt();
+      syslogEquivalent = s.readInt();
+      levelStr = s.readUTF();
+      if (levelStr == null) {
+          levelStr = "";
+      }
+    }
+
+    /**
+     * Serialize level.
+     * @param s serialization stream.
+     * @throws IOException if exception during serialization.
+     */
+    private void writeObject(final ObjectOutputStream s) throws IOException {
+        s.defaultWriteObject();
+        s.writeInt(level);
+        s.writeInt(syslogEquivalent);
+        s.writeUTF(levelStr);
+    }
+
+    /**
+     * Resolved deserialized level to one of the stock instances.
+     * May be overriden in classes derived from Level.
+     * @return resolved object.
+     * @throws ObjectStreamException if exception during resolution.
+     */
+    private Object readResolve() throws ObjectStreamException {
+        //
+        //  if the deserizalized object is exactly an instance of Level
+        //
+        if (getClass() == Level.class) {
+            return toLevel(level);
+        }
+        //
+        //   extension of Level can't substitute stock item
+        //
+        return this;
+    }
+}
\ No newline at end of file

Added: logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Log4jLoggerFactory.java
==============================================================================
--- (empty file)
+++ logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Log4jLoggerFactory.java	Wed Dec 13 14:27:05 2006
@@ -0,0 +1,45 @@
+/*
+ * 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.log4j;
+
+import java.util.Hashtable;
+
+/**
+ * This class is a factory that creates and maintains org.apache.log4j.Loggers
+ * warpping org.slf4j.Loggers.
+ * 
+ * It keeps a hashtable of all created org.apache.log4j.Logger instances so that
+ * all newly created instances are not dulpicates of existing loggers.
+ * 
+ * @author S&eacute;bastien Pennec
+ */
+class Log4jLoggerFactory {
+
+  private static Hashtable log4jLoggers = new Hashtable();
+
+  public static synchronized Logger getLogger(String name) {
+    if (log4jLoggers.containsKey(name)) {
+      return (org.apache.log4j.Logger) log4jLoggers.get(name);
+    } else {
+      Logger log4jLogger = new Logger(name);
+      
+      log4jLoggers.put(name, log4jLogger);
+      return log4jLogger;
+    }
+  }
+
+}

Added: logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Logger.java
==============================================================================
--- (empty file)
+++ logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Logger.java	Wed Dec 13 14:27:05 2006
@@ -0,0 +1,25 @@
+/*
+ * 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.log4j;
+
+public class Logger extends Category {
+
+  Logger(String name) {
+    super(name);
+  }
+
+}

Added: logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Priority.java
==============================================================================
--- (empty file)
+++ logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Priority.java	Wed Dec 13 14:27:05 2006
@@ -0,0 +1,192 @@
+/*
+ * Copyright 1999-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.
+ * 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.
+ */
+
+// Contributors:  Kitching Simon <Simon.Kitching at orange.ch>
+
+package org.apache.log4j;
+
+/**
+   <font color="#AA4444">Refrain from using this class directly, use
+   the {@link Level} class instead</font>.
+
+   @author Ceki G&uuml;lc&uuml; */
+public class Priority {
+
+  transient int level;
+  transient String levelStr;
+  transient int syslogEquivalent;
+
+  public final static int OFF_INT = Integer.MAX_VALUE;
+  public final static int FATAL_INT = 50000;
+  public final static int ERROR_INT = 40000;
+  public final static int WARN_INT  = 30000;
+  public final static int INFO_INT  = 20000;
+  public final static int DEBUG_INT = 10000;
+    //public final static int FINE_INT = DEBUG_INT;
+  public final static int ALL_INT = Integer.MIN_VALUE;
+
+  /**
+   * @deprecated Use {@link Level#FATAL} instead.
+   */
+  final static public Priority FATAL = new Level(FATAL_INT, "FATAL", 0);
+
+  /**
+   * @deprecated Use {@link Level#ERROR} instead.
+   */
+  final static public Priority ERROR = new Level(ERROR_INT, "ERROR", 3);
+
+  /**
+   * @deprecated Use {@link Level#WARN} instead.
+   */
+  final static public Priority WARN  = new Level(WARN_INT, "WARN",  4);
+
+  /**
+   * @deprecated Use {@link Level#INFO} instead.
+   */
+  final static public Priority INFO  = new Level(INFO_INT, "INFO",  6);
+
+  /**
+   * @deprecated Use {@link Level#DEBUG} instead.
+   */
+  final static public Priority DEBUG = new Level(DEBUG_INT, "DEBUG", 7);
+
+
+  /**
+    * Default constructor for deserialization.
+    */
+  protected Priority() {
+      level = DEBUG_INT;
+      levelStr = "DEBUG";
+      syslogEquivalent = 7;
+  }
+
+  /**
+     Instantiate a level object.
+   */
+  protected
+  Priority(int level, String levelStr, int syslogEquivalent) {
+    this.level = level;
+    this.levelStr = levelStr;
+    this.syslogEquivalent = syslogEquivalent;
+  }
+
+  /**
+     Two priorities are equal if their level fields are equal.
+     @since 1.2
+   */
+  public
+  boolean equals(Object o) {
+    if(o instanceof Priority) {
+      Priority r = (Priority) o;
+      return (this.level == r.level);
+    } else {
+      return false;
+    }
+  }
+
+  /**
+     Return the syslog equivalent of this priority as an integer.
+   */
+  public
+  final
+  int getSyslogEquivalent() {
+    return syslogEquivalent;
+  }
+
+
+   
+  /**
+     Returns <code>true</code> if this level has a higher or equal
+     level than the level passed as argument, <code>false</code>
+     otherwise.  
+     
+     <p>You should think twice before overriding the default
+     implementation of <code>isGreaterOrEqual</code> method.
+
+  */
+  public
+  boolean isGreaterOrEqual(Priority r) {
+    return level >= r.level;
+  }
+
+  /**
+     Return all possible priorities as an array of Level objects in
+     descending order.
+
+     @deprecated This method will be removed with no replacement.
+  */
+  public
+  static
+  Priority[] getAllPossiblePriorities() {
+    return new Priority[] {Priority.FATAL, Priority.ERROR, Level.WARN, 
+                                                   Priority.INFO, Priority.DEBUG};
+  }
+
+
+  /**
+     Returns the string representation of this priority.
+   */
+  final
+  public
+  String toString() {
+    return levelStr;
+  }
+
+  /**
+     Returns the integer representation of this level.
+   */
+  public
+  final
+  int toInt() {
+    return level;
+  }
+
+  /**
+   * @deprecated Please use the {@link Level#toLevel(String)} method instead.
+  */
+  public
+  static
+  Priority toPriority(String sArg) {
+    return Level.toLevel(sArg);
+  }
+
+  /**
+   * @deprecated Please use the {@link Level#toLevel(int)} method instead.   
+   */
+  public
+  static
+  Priority toPriority(int val) {
+    return toPriority(val, Priority.DEBUG);
+  }
+
+  /**
+   * @deprecated Please use the {@link Level#toLevel(int, Level)} method instead.   
+  */
+  public
+  static
+  Priority toPriority(int val, Priority defaultPriority) {
+    return Level.toLevel(val, (Level) defaultPriority);
+  }
+
+  /**
+   * @deprecated Please use the {@link Level#toLevel(String, Level)} method instead.   
+   */
+  public
+  static
+  Priority toPriority(String sArg, Priority defaultPriority) {                  
+    return Level.toLevel(sArg, (Level) defaultPriority);
+  }
+}
\ No newline at end of file

Added: logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/package.html
==============================================================================
--- (empty file)
+++ logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/package.html	Wed Dec 13 14:27:05 2006
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+
+
+<html> 
+  <head>
+      <title></title>
+  </head>
+  
+
+  <body>
+  
+ <p>An rather minimal but sufficient implementation redirecting all
+ calls to a log4j logger to a logback logger.</p>
+
+  </body> 
+</html>
+
+

Added: logback/trunk/log4j-bridge/src/test/java/org/apache/log4j/InvokeLog4jTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/log4j-bridge/src/test/java/org/apache/log4j/InvokeLog4jTest.java	Wed Dec 13 14:27:05 2006
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2004-2006 SLF4J.ORG
+ * Copyright (c) 2004-2006 QOS.ch
+ *
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to  deal in  the Software without  restriction, including
+ * without limitation  the rights to  use, copy, modify,  merge, publish,
+ * distribute, and/or sell copies of  the Software, and to permit persons
+ * to whom  the Software is furnished  to do so, provided  that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the  Software and  that both  the above  copyright notice(s)  and this
+ * permission notice appear in supporting documentation.
+ *
+ * THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
+ * EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR  A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF  THIRD PARTY  RIGHTS. IN  NO EVENT  SHALL THE  COPYRIGHT  HOLDER OR
+ * HOLDERS  INCLUDED IN  THIS  NOTICE BE  LIABLE  FOR ANY  CLAIM, OR  ANY
+ * SPECIAL INDIRECT  OR CONSEQUENTIAL DAMAGES, OR  ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS  OF USE, DATA OR PROFITS, WHETHER  IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE  OR OTHER TORTIOUS  ACTION, ARISING OUT OF  OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Except as  contained in  this notice, the  name of a  copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ *
+ */
+
+
+package org.apache.log4j;
+
+import junit.framework.TestCase;
+
+/**
+ * A class that tests the invocation of the org.apache.log4j.Logger class
+ * that belongs to the log4j-bridge package
+ *
+ * @author S&eacute;bastien Pennec
+ * @author Ceki G&uuml;lc&uuml;
+ */
+public class InvokeLog4jTest extends TestCase {
+
+  public void testIsEnabledAPI() {
+    // assume that we are running over slf4j-simple
+    Logger log = Logger.getLogger(InvokeLog4jTest.class.getName());
+    
+    assertTrue(log.isTraceEnabled());
+    assertTrue(log.isDebugEnabled());
+    assertTrue(log.isInfoEnabled());
+    assertTrue(log.isWarnEnabled());
+    assertTrue(log.isErrorEnabled());
+  }
+  
+  public void testPrintAPI() {
+    Logger log = Logger.getLogger(InvokeLog4jTest.class.getName());
+    Exception e = new Exception("just testing");
+    
+    log.debug(null);
+    log.debug("debug message");
+    
+    log.info(null);
+    log.info("info  message");
+    
+    log.warn(null);
+    log.warn("warn message");
+
+    log.error(null);
+    log.error("error message");
+    
+    log.debug(null, e);
+    log.debug("debug message", e);
+    
+    log.info(null, e);    
+    log.info("info  message", e);
+    
+    log.warn(null, e);
+    log.warn("warn message", e);
+    
+    log.error(null, e);
+    log.error("error message", e);
+  }
+}

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java	Wed Dec 13 14:27:05 2006
@@ -404,7 +404,8 @@
     filterAndLog(marker, Level.DEBUG, msg, null, null);
   }
   
-  final void filterAndLog(final Marker marker, final Level level, final String msg, final Object[] params,
+
+  public final void filterAndLog(final String localFQCN, final Marker marker, final Level level, final String msg, final Object[] params,
       final Throwable t) {
   
     final FilterReply decision = loggerContext.getTurboFilterChainDecision(marker, this, Level.DEBUG, msg, params, t);
@@ -417,9 +418,16 @@
       return;
     }
     
-    LoggingEvent le = new LoggingEvent(FQCN, this, level, msg, t, params);
+    LoggingEvent le = new LoggingEvent(localFQCN, this, level, msg, t, params);
     le.setMarker(marker);
     callAppenders(le);
+    
+  }
+
+  
+  final void filterAndLog(final Marker marker, final Level level, final String msg, final Object[] params,
+      final Throwable t) {
+    filterAndLog(FQCN, marker, level, msg, params, t);
   }
 
   public void debug(Marker marker, String format, Object arg) {

Modified: logback/trunk/pom.xml
==============================================================================
--- logback/trunk/pom.xml	(original)
+++ logback/trunk/pom.xml	Wed Dec 13 14:27:05 2006
@@ -24,6 +24,7 @@
         <module>logback-site</module>
         <module>logback-skin</module>
         <module>logback-examples</module>
+        <module>log4j-bridge</module>
     </modules>
 
     <dependencies>
@@ -129,6 +130,14 @@
             </extension>
         </extensions>
         <plugins>
+        	 <plugin>
+						  <groupId>org.apache.maven.plugins</groupId>
+						  <artifactId>maven-compiler-plugin</artifactId>
+						  <configuration>
+							  <source>1.5</source>
+							  <target>1.5</target>
+						  </configuration>
+			      </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-source-plugin</artifactId>



More information about the logback-dev mailing list