You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by pi...@apache.org on 2004/11/03 18:23:21 UTC

svn commit: rev 56494 - in cocoon/whiteboard/kernel/sources: blocks/commons-dbcp extensions/logging extensions/logging/src extensions/logging/src/org extensions/logging/src/org/apache extensions/logging/src/org/apache/cocoon extensions/logging/src/org/apache/cocoon/kernel extensions/logging/src/org/apache/cocoon/kernel/plugins interfaces/jdbc-datasource modules/commons-collections modules/commons-pool runtime/org/apache/cocoon/kernel/plugins

Author: pier
Date: Wed Nov  3 09:23:19 2004
New Revision: 56494

Added:
   cocoon/whiteboard/kernel/sources/blocks/commons-dbcp/cocoon.xml
   cocoon/whiteboard/kernel/sources/extensions/logging/cocoon.xml
   cocoon/whiteboard/kernel/sources/extensions/logging/src/
   cocoon/whiteboard/kernel/sources/extensions/logging/src/org/
   cocoon/whiteboard/kernel/sources/extensions/logging/src/org/apache/
   cocoon/whiteboard/kernel/sources/extensions/logging/src/org/apache/cocoon/
   cocoon/whiteboard/kernel/sources/extensions/logging/src/org/apache/cocoon/kernel/
   cocoon/whiteboard/kernel/sources/extensions/logging/src/org/apache/cocoon/kernel/plugins/
   cocoon/whiteboard/kernel/sources/extensions/logging/src/org/apache/cocoon/kernel/plugins/LoggingPlugin.java
   cocoon/whiteboard/kernel/sources/interfaces/jdbc-datasource/cocoon.xml
   cocoon/whiteboard/kernel/sources/modules/commons-collections/cocoon.xml
   cocoon/whiteboard/kernel/sources/modules/commons-pool/cocoon.xml
Removed:
   cocoon/whiteboard/kernel/sources/blocks/commons-dbcp/block.xml
   cocoon/whiteboard/kernel/sources/extensions/logging/block.xml
   cocoon/whiteboard/kernel/sources/interfaces/jdbc-datasource/block.xml
   cocoon/whiteboard/kernel/sources/modules/commons-collections/block.xml
   cocoon/whiteboard/kernel/sources/modules/commons-pool/block.xml
   cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/plugins/LoggingPlugin.java
Log:
Moving LoggingPlugin sources together with the logging plugin.
Renaming descriptor files from "block.xml" to "cocoon.xml" as there are different kinds of "block" now.

Added: cocoon/whiteboard/kernel/sources/blocks/commons-dbcp/cocoon.xml
==============================================================================
--- (empty file)
+++ cocoon/whiteboard/kernel/sources/blocks/commons-dbcp/cocoon.xml	Wed Nov  3 09:23:19 2004
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<block xmlns="http://apache.org/cocoon/blocks/descriptor/1.0"
+    id="http://cocoon.apache.org/blocks/jakarta/commons-dbcp/1.2.1">
+
+  <requirements>
+    <requires module="http://cocoon.apache.org/abstracts/jakarta/commons-pool/1.2"/>
+  </requirements>
+
+  <implementations>  
+    <implements interface="http://cocoon.apache.org/blocks/interfaces/jdbc-datasource/1.0"/>
+  </implementations>
+
+  <libraries>
+    <library href="commons-dbcp-1.2.1.jar"/>
+  </libraries>
+  
+  <provides component="org.apache.commons.dbcp.BasicDataSource"/>
+
+</block>

Added: cocoon/whiteboard/kernel/sources/extensions/logging/cocoon.xml
==============================================================================
--- (empty file)
+++ cocoon/whiteboard/kernel/sources/extensions/logging/cocoon.xml	Wed Nov  3 09:23:19 2004
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<extension xmlns="http://apache.org/cocoon/blocks/descriptor/1.0"
+    id="http://cocoon.apache.org/blocks/plugins/logging/1.0.0">
+
+  <plugin
+    class="org.apache.cocoon.kernel.plugins.LoggingPlugin"
+    configuration-element="logging"/>
+
+  <libraries>
+    <library href="commons-logging-1.0.4.jar"/>
+    <library href="log4j-1.2.9.jar"/>
+  </libraries>
+
+</extension>

Added: cocoon/whiteboard/kernel/sources/extensions/logging/src/org/apache/cocoon/kernel/plugins/LoggingPlugin.java
==============================================================================
--- (empty file)
+++ cocoon/whiteboard/kernel/sources/extensions/logging/src/org/apache/cocoon/kernel/plugins/LoggingPlugin.java	Wed Nov  3 09:23:19 2004
@@ -0,0 +1,268 @@
+/* =============================================================================== *
+ * Copyright (C) 1999-2004, The Apache Software Foundation.   All rights reserved. *
+ *                                                                                 *
+ * 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.cocoon.kernel.plugins;
+
+import java.net.URL;
+import java.util.Enumeration;
+
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.impl.Log4jFactory;
+import org.apache.log4j.Appender;
+import org.apache.log4j.Category;
+import org.apache.log4j.Level;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.apache.log4j.spi.HierarchyEventListener;
+import org.apache.log4j.spi.LoggerFactory;
+import org.apache.log4j.spi.LoggerRepository;
+import org.apache.log4j.spi.RepositorySelector;
+import org.apache.log4j.xml.DOMConfigurator;
+
+/**
+ * <p>The {@link LoggingPlugin} enables the use of Log4J and Commons-Logging
+ * in a kernel-aware way.</p> 
+ *
+ * @author <a href="mailto:pier@apache.org">Pier Fumagalli</a>
+ * @author Copyright &copy; 2000-2004 <a href="http://www.apache.org/">The Apache
+ *         Software Foundation</a>. All rights reserved.
+ */
+public class LoggingPlugin extends AbstractPlugin
+implements LoggerRepository, RepositorySelector {
+
+    /** <p>The original {@link LoggerRepository} of Log4J.</p> */
+    private LoggerRepository repository = null;
+    /** <p>The logger originally associated with the kernel.</p> */
+    private org.apache.cocoon.kernel.startup.Logger original = null;
+
+    /**
+     * <p>Create a new {@link LoggingPlugin} instance.</p>
+     */
+    public LoggingPlugin() {
+        this.repository = LogManager.getLoggerRepository();
+    }
+
+    public void initialize() {
+        /* Configure Log4J if we were told to do so */
+        String conf = this.getConfiguration().getStringAttribute("log4j", null);
+        if (conf != null) try {
+            URL url = new URL(this.getConfiguration().locationURL(), conf);
+            DOMConfigurator configurator = new DOMConfigurator();
+            configurator.doConfigure(url, this.repository);
+        } catch (Throwable throwable) {
+            this.error("Cannot configure Log4J", throwable);
+        }
+        
+        /* Error or no error, we _are_ using Log4J, no questions asked */
+        this.debug("Switching logger implementation");
+        this.original = this.getKernel().getLogger();
+        this.getKernel().setLogger(new Wrapper(Logger.getLogger("kernel")));
+        this.debug("Switched logger implementation");
+
+        /* Replace the Log4J Logger Repository */
+        this.debug("Configuring Log4J");
+        try {
+            LogManager.setRepositorySelector(this, null);
+        } catch (Throwable t) {
+            this.error("Unable to configure Log4J repository selector", t);
+        }
+        
+        /* And make sure that commons has the Log4J factory configured */
+        String factory = Log4jFactory.class.getName();
+        System.setProperty(LogFactory.FACTORY_PROPERTY, factory);
+        LogFactory.getLog(this.getClass()).debug("Commons-Logging configured");
+    }
+
+    public void destroy() {
+        this.debug("Restoring logger implementation");
+        this.getKernel().setLogger(this.original);
+        this.debug("Restored logger implementation");
+        this.repository.shutdown();
+    }
+
+    /* =========================================================================== */
+    /* UNDERSTANDABLE LOG4J METHODS                                                */
+    /* =========================================================================== */
+
+    /**
+     * <p>Return ourselves.</p>
+     */
+    public LoggerRepository getLoggerRepository() {
+        return(this);
+    }
+
+    /**
+     * <p>Return the logger associated with the calling block.</p>
+     */
+    public Logger getLogger(String arg0) {
+        return this.repository.getLogger(this.getLoggerName(arg0));
+    }
+
+    /**
+     * <p>Return the logger associated with the calling block.</p>
+     */
+    public Logger getLogger(String arg0, LoggerFactory arg1) {
+        return this.repository.getLogger(this.getLoggerName(arg0), arg1);
+    }
+
+    /**
+     * <p>Return the logger associated with the calling block.</p>
+     */
+    public Logger getRootLogger() {
+        return this.repository.getLogger(this.getLoggerName(null));
+    }
+
+    /**
+     * <p>Check if the logger specified exists.</p>
+     */
+    public Logger exists(String arg0) {
+        return this.repository.exists(this.getLoggerName(arg0));
+    }
+
+    /**
+     * <p>Canonicalize the name of the logger to return.</p>
+     */
+    public String getLoggerName(String arg0) {
+        String name = Utilities.getCallerName();
+        if (name == null) {
+            if (arg0 == null) return "unknown";
+            if (arg0.length() == 0) return "unknown";
+            return arg0;
+        } else {
+            if (arg0 == null) return name;
+            if (arg0.length() == 0) return name;
+            return (name + "." + arg0);
+        }
+    }
+
+    /**
+     * <p>Simply ignore this call from the kernel.</p>
+     */
+    public void resetConfiguration() {
+        // Nothing to do...
+    }
+
+    /**
+     * <p>Simply ignore this call from the kernel.</p>
+     */
+    public void shutdown() {
+        // Nothing to do...
+    }
+
+    /* =========================================================================== */
+    /* GOD KNOWS WHAT THIS DOES METHODS GO STRAIGHT TO LOG4J (TOO COMPLICATED)     */
+    /* =========================================================================== */
+
+    /**
+     * <p>Forwarded directly to the Log4J original {@link LoggerRepository}.</p>
+     */
+    public void addHierarchyEventListener(HierarchyEventListener arg0) {
+        this.repository.addHierarchyEventListener(arg0);
+    }
+
+    /**
+     * <p>Forwarded directly to the Log4J original {@link LoggerRepository}.</p>
+     */
+    public boolean isDisabled(int arg0) {
+        return this.repository.isDisabled(arg0);
+    }
+
+    /**
+     * <p>Forwarded directly to the Log4J original {@link LoggerRepository}.</p>
+     */
+    public void setThreshold(Level arg0) {
+        this.repository.setThreshold(arg0);
+    }
+
+    /**
+     * <p>Forwarded directly to the Log4J original {@link LoggerRepository}.</p>
+     */
+    public void setThreshold(String arg0) {
+        this.repository.setThreshold(arg0);
+    }
+
+    /**
+     * <p>Forwarded directly to the Log4J original {@link LoggerRepository}.</p>
+     */
+    public void emitNoAppenderWarning(Category arg0) {
+        this.repository.emitNoAppenderWarning(arg0);
+    }
+
+    /**
+     * <p>Forwarded directly to the Log4J original {@link LoggerRepository}.</p>
+     */
+    public Level getThreshold() {
+        return this.repository.getThreshold();
+    }
+
+    /**
+     * <p>Forwarded directly to the Log4J original {@link LoggerRepository}.</p>
+     */
+    public Enumeration getCurrentLoggers() {
+        return this.repository.getCurrentLoggers();
+    }
+
+    /**
+     * <p>Forwarded directly to the Log4J original {@link LoggerRepository}.</p>
+     */
+    public Enumeration getCurrentCategories() {
+        return this.repository.getCurrentCategories();
+    }
+
+    /**
+     * <p>Forwarded directly to the Log4J original {@link LoggerRepository}.</p>
+     */
+    public void fireAddAppenderEvent(Category arg0, Appender arg1) {
+        this.repository.fireAddAppenderEvent(arg0, arg1);
+    }
+
+    /* =========================================================================== */
+    /* WRAPPER FOR THE KERNEL LOGGER AROUND LOG4J                                  */
+    /* =========================================================================== */
+    
+    /**
+     * <p>A simple wrapper for the internal kernel logger.</p>
+     */
+    private static class Wrapper extends org.apache.cocoon.kernel.startup.Logger {
+
+        private Logger logger = null;
+
+        private Wrapper(Logger logger) {
+            if (logger == null) throw new NullPointerException("Null logger");
+            this.logger = logger;
+        }
+
+        public void debug(String message) {
+            this.logger.debug(message);
+        }
+        
+        public void debug(String message, Throwable throwable) {
+            this.logger.debug(message, throwable);
+        }
+        
+        public void log(String message) {
+            this.logger.info(message);
+        }
+        
+        public void log(String message, Throwable throwable) {
+            this.logger.info(message, throwable);
+        }
+       
+        public void error(String message) {
+            this.logger.error(message);
+        }
+        
+        public void error(String message, Throwable throwable) {
+            this.logger.error(message, throwable);
+        }
+    }
+}

Added: cocoon/whiteboard/kernel/sources/interfaces/jdbc-datasource/cocoon.xml
==============================================================================
--- (empty file)
+++ cocoon/whiteboard/kernel/sources/interfaces/jdbc-datasource/cocoon.xml	Wed Nov  3 09:23:19 2004
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<interface xmlns="http://apache.org/cocoon/blocks/descriptor/1.0"
+    id="http://cocoon.apache.org/blocks/interfaces/jdbc-datasource/1.0">
+
+  <exposes interface="javax.sql.DataSource"/>
+
+</interface>
\ No newline at end of file

Added: cocoon/whiteboard/kernel/sources/modules/commons-collections/cocoon.xml
==============================================================================
--- (empty file)
+++ cocoon/whiteboard/kernel/sources/modules/commons-collections/cocoon.xml	Wed Nov  3 09:23:19 2004
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<module xmlns="http://apache.org/cocoon/blocks/descriptor/1.0"
+    id="http://cocoon.apache.org/abstracts/jakarta/commons-collections/3.1">
+  
+  <libraries>
+    <library href="commons-collections-3.1.jar"/>
+  </libraries>
+
+</module>

Added: cocoon/whiteboard/kernel/sources/modules/commons-pool/cocoon.xml
==============================================================================
--- (empty file)
+++ cocoon/whiteboard/kernel/sources/modules/commons-pool/cocoon.xml	Wed Nov  3 09:23:19 2004
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<module xmlns="http://apache.org/cocoon/blocks/descriptor/1.0"
+    id="http://cocoon.apache.org/abstracts/jakarta/commons-pool/1.2">
+
+  <extensions>
+    <extends module="http://cocoon.apache.org/abstracts/jakarta/commons-collections/3.1"/>
+  </extensions>
+
+  <libraries>
+    <library href="commons-pool-1.2.jar"/>
+  </libraries>
+
+</module>