Author: ceki
Date: Mon Sep 11 22:30:22 2006
New Revision: 646

Added:
   slf4j/trunk/log4j-over-slf4j/pom.xml
   slf4j/trunk/log4j-over-slf4j/src/
   slf4j/trunk/log4j-over-slf4j/src/main/
   slf4j/trunk/log4j-over-slf4j/src/main/java/
   slf4j/trunk/log4j-over-slf4j/src/main/java/org/
   slf4j/trunk/log4j-over-slf4j/src/main/java/org/apache/
   slf4j/trunk/log4j-over-slf4j/src/main/java/org/apache/log4j/
   
slf4j/trunk/log4j-over-slf4j/src/main/java/org/apache/log4j/Log4jLoggerFactory.java
   slf4j/trunk/log4j-over-slf4j/src/main/java/org/apache/log4j/Logger.java
   slf4j/trunk/log4j-over-slf4j/src/test/
   slf4j/trunk/log4j-over-slf4j/src/test/java/
   slf4j/trunk/log4j-over-slf4j/src/test/java/org/
   slf4j/trunk/log4j-over-slf4j/src/test/java/org/apache/
   slf4j/trunk/log4j-over-slf4j/src/test/java/org/apache/log4j/
   
slf4j/trunk/log4j-over-slf4j/src/test/java/org/apache/log4j/InvokeLog4jTest.java

Log:


Added: slf4j/trunk/log4j-over-slf4j/pom.xml
==============================================================================
--- (empty file)
+++ slf4j/trunk/log4j-over-slf4j/pom.xml        Mon Sep 11 22:30:22 2006
@@ -0,0 +1,31 @@
+<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>org.slf4j</groupId>
+               <artifactId>slf4j</artifactId>
+               <version>1.1.0</version>
+       </parent>
+       
+       <modelVersion>4.0.0</modelVersion>
+
+       <groupId>org.slf4j</groupId>
+       <artifactId>log4j-over-slf4j</artifactId>
+       <version>${parent.version}</version>
+       <packaging>jar</packaging>
+       <name>Log4j Implemented Over SLF4J</name>
+
+       <url>http://www.slf4j.org</url>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+               </dependency>
+
+
+  </dependencies>
+
+
+</project>
\ No newline at end of file

Added: 
slf4j/trunk/log4j-over-slf4j/src/main/java/org/apache/log4j/Log4jLoggerFactory.java
==============================================================================
--- (empty file)
+++ 
slf4j/trunk/log4j-over-slf4j/src/main/java/org/apache/log4j/Log4jLoggerFactory.java
 Mon Sep 11 22:30:22 2006
@@ -0,0 +1,38 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * 
+ * Copyright (C) 1999-2006, QOS.ch
+ * 
+ * This library is free software, you can redistribute it and/or modify it 
under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+
+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
+ */
+public class Log4jLoggerFactory {
+
+       private static Hashtable log4jLoggers = new Hashtable();
+
+       public static 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: slf4j/trunk/log4j-over-slf4j/src/main/java/org/apache/log4j/Logger.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/log4j-over-slf4j/src/main/java/org/apache/log4j/Logger.java     
Mon Sep 11 22:30:22 2006
@@ -0,0 +1,174 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * 
+ * Copyright (C) 1999-2006, QOS.ch
+ * 
+ * This library is free software, you can redistribute it and/or modify it 
under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+
+package org.apache.log4j;
+
+import org.slf4j.LoggerFactory;
+
+/**
+ * <p>
+ * This class is a re-implementation of the org.apache.log4j.Logger class. It
+ * uses a org.slf4j.Logger object to delegate the actual logging to a
+ * user-chosen implementation. 
+ * </p>
+ * <p>
+ * Its printing methods that are shared with the
+ * org.slf4j.Logger interface redirect the logging requests to the
+ * org.slf4j.Logger. Those methods are debug, info, warn and error. However, 
the
+ * methods that are now present in the org.slf4j.Logger interface are not
+ * implemented. Those are the trace and fatal methods.
+ * </p>
+ * 
+ * @author S&eacute;bastien Pennec
+ */
+public class Logger {
+
+       private String name;
+
+       private org.slf4j.Logger lbLogger;
+
+       protected Logger(String name) {
+               this.name = name;
+               lbLogger = LoggerFactory.getLogger(name);
+       }
+
+       public static Logger getLogger(String name) {
+               return Log4jLoggerFactory.getLogger(name);
+       }
+
+       public static Logger getLogger(Class clazz) {
+               return getLogger(clazz.getName());
+       }
+
+       public static Logger getRootLogger() {
+               return getLogger("root");
+       }
+
+       public String getName() {
+               return name;
+       }
+
+       public boolean isDebugEnabled() {
+               return lbLogger.isDebugEnabled();
+       }
+
+       public void debug(Object message) {
+               /**
+                * In the debug(Object message) method, as well as other 
printing methods,
+                * we consider that the message passed as a parameter is a 
String. Object
+                * that usually need an ObjectRenderer cannot be sent to these 
methods.
+                */
+               lbLogger.debug((String) message);
+       }
+
+       public void debug(Object message, Throwable t) {
+               lbLogger.debug((String) message, t);
+       }
+
+       public void debug(Object messagePattern, Object arg) {
+               lbLogger.debug((String) messagePattern, arg);
+       }
+
+       public void debug(Object messagePattern, Object arg1, Object arg2) {
+               lbLogger.debug((String) messagePattern, arg1, arg2);
+       }
+
+       public boolean isInfoEnabled() {
+               return lbLogger.isInfoEnabled();
+       }
+
+       public void info(Object message) {
+               lbLogger.info((String) message);
+       }
+
+       public void info(Object message, Throwable t) {
+               lbLogger.info((String) message, t);
+       }
+
+       public void info(Object messagePattern, Object arg) {
+               lbLogger.info((String) messagePattern, arg);
+       }
+
+       public void info(Object messagePattern, Object arg1, Object arg2) {
+               lbLogger.info((String) messagePattern, arg1, arg2);
+       }
+
+       public boolean isWarnEnabled() {
+               return lbLogger.isWarnEnabled();
+       }
+
+       public void warn(Object message) {
+               lbLogger.warn((String) message);
+       }
+
+       public void warn(Object message, Throwable t) {
+               lbLogger.warn((String) message, t);
+       }
+
+       public void warn(Object messagePattern, Object arg) {
+               lbLogger.warn((String) messagePattern, arg);
+       }
+
+       public void warn(Object messagePattern, Object arg1, Object arg2) {
+               lbLogger.warn((String) messagePattern, arg1, arg2);
+       }
+
+       public boolean isErrorEnabled() {
+               return lbLogger.isErrorEnabled();
+       }
+
+       public void error(Object message) {
+               lbLogger.error((String) message);
+       }
+
+       public void error(Object message, Throwable t) {
+               lbLogger.error((String) message, t);
+       }
+
+       public void error(Object messagePattern, Object arg) {
+               lbLogger.error((String) messagePattern, arg);
+       }
+
+       public void error(Object messagePattern, Object arg1, Object arg2) {
+               lbLogger.error((String) messagePattern, arg1, arg2);
+       }
+
+       // public void log(String fqcn, Level level, String message, Throwable 
t) {
+       // //FIXME improve + complete impl.
+       // Logger logger = getLogger(fqcn);
+       // if (Level.DEBUG.equals(level)) {
+       // logger.debug(message, t);
+       // } else if (Level.INFO.equals(level)) {
+       // logger.info(message, t);
+       // } else if (Level.WARN.equals(level)) {
+       // logger.info(message, t);
+       // } else if (Level.ERROR.equals(level)) {
+       // logger.info(message, t);
+       // }
+       // }
+       //  
+       // public boolean isEnabledFor(Level level) {
+       // //FIXME improve + complete impl.
+       // if(Level.DEBUG.equals(level) && lbLogger.isDebugEnabled()) {
+       // return true;
+       // }
+       // if(Level.INFO.equals(level) && lbLogger.isInfoEnabled()) {
+       // return true;
+       // }
+       // if(Level.WARN.equals(level) && lbLogger.isWarnEnabled()) {
+       // return true;
+       // }
+       // if(Level.ERROR.equals(level) && lbLogger.isErrorEnabled()) {
+       // return true;
+       // }
+       // return false;
+       // }
+
+}
\ No newline at end of file

Added: 
slf4j/trunk/log4j-over-slf4j/src/test/java/org/apache/log4j/InvokeLog4jTest.java
==============================================================================
--- (empty file)
+++ 
slf4j/trunk/log4j-over-slf4j/src/test/java/org/apache/log4j/InvokeLog4jTest.java
    Mon Sep 11 22:30:22 2006
@@ -0,0 +1,84 @@
+/*
+ * 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-over-slf4j package
+ *
+ * @author S&eacute;bastien Pennec
+ */
+public class InvokeLog4jTest extends TestCase {
+
+  public void testIsEnabledAPI() {
+    // assume that we are running over slf4j-simple
+    Logger log = Logger.getLogger(InvokeLog4jTest.class.getName());
+    assertFalse(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);
+  }
+}
_______________________________________________
dev mailing list
[email protected]
http://www.slf4j.org/mailman/listinfo/dev

Reply via email to