SLING-3580 - Remove embedded Tomcat Juli jar by overriding LogFactory which delegates to Slf4j

Adding Log and LogFactory implementations which delegates to Slf4j

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1596210 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index 21ed802..3a67c1f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -59,10 +59,12 @@
         <extensions>true</extensions>
         <configuration>
           <instructions>
+            <Export-Package>
+              !org.apache.juli.logging
+            </Export-Package>
             <Embed-Dependency>
               org.apache.sling.commons.osgi;inline=org/apache/sling/commons/osgi/PropertiesUtil.class,
               tomcat-jdbc,
-              tomcat-juli
             </Embed-Dependency>
           </instructions>
         </configuration>
@@ -131,11 +133,12 @@
       <groupId>org.apache.tomcat</groupId>
       <artifactId>tomcat-jdbc</artifactId>
       <version>7.0.53</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.tomcat</groupId>
-      <artifactId>tomcat-juli</artifactId>
-      <version>7.0.53</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.tomcat</groupId>
+          <artifactId>tomcat-juli</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
 
     <!-- OSGi test -->
diff --git a/src/main/java/org/apache/juli/logging/DirectJDKLog.java b/src/main/java/org/apache/juli/logging/DirectJDKLog.java
deleted file mode 100644
index f49ac08..0000000
--- a/src/main/java/org/apache/juli/logging/DirectJDKLog.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.juli.logging;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Overriding the DirectJDKLog impl to delegate the logging to Slf4j
- */
-@SuppressWarnings("UnusedDeclaration")
-class DirectJDKLog implements Log {
-    private final Logger logger;
-
-    public DirectJDKLog(String name) {
-        this.logger = LoggerFactory.getLogger(name);
-    }
-
-    static Log getInstance(String name) {
-        return new DirectJDKLog( name );
-    }
-
-    public boolean isDebugEnabled() {
-        return logger.isDebugEnabled();
-    }
-
-    public boolean isErrorEnabled() {
-        return logger.isErrorEnabled();
-    }
-
-    public boolean isFatalEnabled() {
-        return logger.isErrorEnabled();
-    }
-
-    public boolean isInfoEnabled() {
-        return logger.isInfoEnabled();
-    }
-
-    public boolean isTraceEnabled() {
-        return logger.isTraceEnabled();
-    }
-
-    public boolean isWarnEnabled() {
-        return logger.isWarnEnabled();
-    }
-
-    public void trace(Object message) {
-        logger.trace(String.valueOf(message));
-    }
-
-    public void trace(Object message, Throwable t) {
-        logger.trace(String.valueOf(message), t);
-    }
-
-    public void debug(Object message) {
-        logger.debug(String.valueOf(message));
-    }
-
-    public void debug(Object message, Throwable t) {
-        logger.debug(String.valueOf(message), t);
-    }
-
-    public void info(Object message) {
-        logger.info(String.valueOf(message));
-    }
-
-    public void info(Object message, Throwable t) {
-        logger.info(String.valueOf(message), t);
-    }
-
-    public void warn(Object message) {
-        logger.warn(String.valueOf(message));
-    }
-
-    public void warn(Object message, Throwable t) {
-        logger.warn(String.valueOf(message), t);
-    }
-
-    public void error(Object message) {
-        logger.error(String.valueOf(message));
-    }
-
-    public void error(Object message, Throwable t) {
-        logger.error(String.valueOf(message), t);
-    }
-
-    public void fatal(Object message) {
-        logger.error(String.valueOf(message));
-    }
-
-    public void fatal(Object message, Throwable t) {
-        logger.error(String.valueOf(message), t);
-    }
-}
diff --git a/src/main/java/org/apache/juli/logging/Log.java b/src/main/java/org/apache/juli/logging/Log.java
new file mode 100644
index 0000000..daf5226
--- /dev/null
+++ b/src/main/java/org/apache/juli/logging/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.juli.logging;
+
+/**
+ * <p>A simple logging interface abstracting logging APIs.  In order to be
+ * instantiated successfully by {@link LogFactory}, classes that implement
+ * this interface must have a constructor that takes a single String
+ * parameter representing the "name" of this Log.</p>
+ *
+ * <p> The six logging levels used by <code>Log</code> are (in order):
+ * <ol>
+ * <li>trace (the least serious)</li>
+ * <li>debug</li>
+ * <li>info</li>
+ * <li>warn</li>
+ * <li>error</li>
+ * <li>fatal (the most serious)</li>
+ * </ol>
+ * The mapping of these log levels to the concepts used by the underlying
+ * logging system is implementation dependent.
+ * The implementation should ensure, though, that this ordering behaves
+ * as expected.</p>
+ *
+ * <p>Performance is often a logging concern.
+ * By examining the appropriate property,
+ * a component can avoid expensive operations (producing information
+ * to be logged).</p>
+ *
+ * <p> For example,
+ * <code><pre>
+ *    if (log.isDebugEnabled()) {
+ *        ... do something expensive ...
+ *        log.debug(theResult);
+ *    }
+ * </pre></code>
+ * </p>
+ *
+ * <p>Configuration of the underlying logging system will generally be done
+ * external to the Logging APIs, through whatever mechanism is supported by
+ * that system.</p>
+ *
+ * @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
+ * @author Rod Waldhoff
+ */
+@SuppressWarnings("UnusedDeclaration")
+public interface Log {
+
+
+    // ----------------------------------------------------- Logging Properties
+
+
+    /**
+     * <p> Is debug logging currently enabled? </p>
+     *
+     * <p> Call this method to prevent having to perform expensive operations
+     * (for example, <code>String</code> concatenation)
+     * when the log level is more than debug. </p>
+     */
+    public boolean isDebugEnabled();
+
+
+    /**
+     * <p> Is error logging currently enabled? </p>
+     *
+     * <p> Call this method to prevent having to perform expensive operations
+     * (for example, <code>String</code> concatenation)
+     * when the log level is more than error. </p>
+     */
+    public boolean isErrorEnabled();
+
+
+    /**
+     * <p> Is fatal logging currently enabled? </p>
+     *
+     * <p> Call this method to prevent having to perform expensive operations
+     * (for example, <code>String</code> concatenation)
+     * when the log level is more than fatal. </p>
+     */
+    public boolean isFatalEnabled();
+
+
+    /**
+     * <p> Is info logging currently enabled? </p>
+     *
+     * <p> Call this method to prevent having to perform expensive operations
+     * (for example, <code>String</code> concatenation)
+     * when the log level is more than info. </p>
+     */
+    public boolean isInfoEnabled();
+
+
+    /**
+     * <p> Is trace logging currently enabled? </p>
+     *
+     * <p> Call this method to prevent having to perform expensive operations
+     * (for example, <code>String</code> concatenation)
+     * when the log level is more than trace. </p>
+     */
+    public boolean isTraceEnabled();
+
+
+    /**
+     * <p> Is warn logging currently enabled? </p>
+     *
+     * <p> Call this method to prevent having to perform expensive operations
+     * (for example, <code>String</code> concatenation)
+     * when the log level is more than warn. </p>
+     */
+    public boolean isWarnEnabled();
+
+
+    // -------------------------------------------------------- Logging Methods
+
+
+    /**
+     * <p> Log a message with trace log level. </p>
+     *
+     * @param message log this message
+     */
+    public void trace(Object message);
+
+
+    /**
+     * <p> Log an error with trace log level. </p>
+     *
+     * @param message log this message
+     * @param t log this cause
+     */
+    public void trace(Object message, Throwable t);
+
+
+    /**
+     * <p> Log a message with debug log level. </p>
+     *
+     * @param message log this message
+     */
+    public void debug(Object message);
+
+
+    /**
+     * <p> Log an error with debug log level. </p>
+     *
+     * @param message log this message
+     * @param t log this cause
+     */
+    public void debug(Object message, Throwable t);
+
+
+    /**
+     * <p> Log a message with info log level. </p>
+     *
+     * @param message log this message
+     */
+    public void info(Object message);
+
+
+    /**
+     * <p> Log an error with info log level. </p>
+     *
+     * @param message log this message
+     * @param t log this cause
+     */
+    public void info(Object message, Throwable t);
+
+
+    /**
+     * <p> Log a message with warn log level. </p>
+     *
+     * @param message log this message
+     */
+    public void warn(Object message);
+
+
+    /**
+     * <p> Log an error with warn log level. </p>
+     *
+     * @param message log this message
+     * @param t log this cause
+     */
+    public void warn(Object message, Throwable t);
+
+
+    /**
+     * <p> Log a message with error log level. </p>
+     *
+     * @param message log this message
+     */
+    public void error(Object message);
+
+
+    /**
+     * <p> Log an error with error log level. </p>
+     *
+     * @param message log this message
+     * @param t log this cause
+     */
+    public void error(Object message, Throwable t);
+
+
+    /**
+     * <p> Log a message with fatal log level. </p>
+     *
+     * @param message log this message
+     */
+    public void fatal(Object message);
+
+
+    /**
+     * <p> Log an error with fatal log level. </p>
+     *
+     * @param message log this message
+     * @param t log this cause
+     */
+    public void fatal(Object message, Throwable t);
+
+
+}
diff --git a/src/main/java/org/apache/juli/logging/LogFactory.java b/src/main/java/org/apache/juli/logging/LogFactory.java
new file mode 100644
index 0000000..c93908c
--- /dev/null
+++ b/src/main/java/org/apache/juli/logging/LogFactory.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.juli.logging;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LogFactory {
+
+    public static Log getLog(String name){
+        return new Slf4jLog(name);
+    }
+
+    public static Log getLog(Class<?> clazz){
+        return getLog(clazz.getName());
+    }
+
+    private static class Slf4jLog implements Log {
+        private final Logger logger;
+
+        public Slf4jLog(String name) {
+            this.logger = LoggerFactory.getLogger(name);
+        }
+
+        public boolean isDebugEnabled() {
+            return logger.isDebugEnabled();
+        }
+
+        public boolean isErrorEnabled() {
+            return logger.isErrorEnabled();
+        }
+
+        public boolean isFatalEnabled() {
+            return logger.isErrorEnabled();
+        }
+
+        public boolean isInfoEnabled() {
+            return logger.isInfoEnabled();
+        }
+
+        public boolean isTraceEnabled() {
+            return logger.isTraceEnabled();
+        }
+
+        public boolean isWarnEnabled() {
+            return logger.isWarnEnabled();
+        }
+
+        public void trace(Object message) {
+            logger.trace(String.valueOf(message));
+        }
+
+        public void trace(Object message, Throwable t) {
+            logger.trace(String.valueOf(message), t);
+        }
+
+        public void debug(Object message) {
+            logger.debug(String.valueOf(message));
+        }
+
+        public void debug(Object message, Throwable t) {
+            logger.debug(String.valueOf(message), t);
+        }
+
+        public void info(Object message) {
+            logger.info(String.valueOf(message));
+        }
+
+        public void info(Object message, Throwable t) {
+            logger.info(String.valueOf(message), t);
+        }
+
+        public void warn(Object message) {
+            logger.warn(String.valueOf(message));
+        }
+
+        public void warn(Object message, Throwable t) {
+            logger.warn(String.valueOf(message), t);
+        }
+
+        public void error(Object message) {
+            logger.error(String.valueOf(message));
+        }
+
+        public void error(Object message, Throwable t) {
+            logger.error(String.valueOf(message), t);
+        }
+
+        public void fatal(Object message) {
+            logger.error(String.valueOf(message));
+        }
+
+        public void fatal(Object message, Throwable t) {
+            logger.error(String.valueOf(message), t);
+        }
+    }
+}