cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: rev 36285 - in cocoon/branches/BRANCH_2_1_X: . src/blocks/portal/java/org/apache/cocoon/portlet src/java/org/apache/cocoon/servlet src/webapp/WEB-INF
Date Thu, 12 Aug 2004 13:10:54 GMT
Author: cziegeler
Date: Thu Aug 12 06:10:49 2004
New Revision: 36285

Modified:
   cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/servlet/CocoonServlet.java
   cocoon/branches/BRANCH_2_1_X/src/webapp/WEB-INF/web.xml
   cocoon/branches/BRANCH_2_1_X/status.xml
Log:
Sync log4j support

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java
Thu Aug 12 06:10:49 2004
@@ -15,11 +15,13 @@
  */
 package org.apache.cocoon.portlet;
 
+import org.apache.avalon.excalibur.logger.Log4JLoggerManager;
 import org.apache.avalon.excalibur.logger.LogKitLoggerManager;
 import org.apache.avalon.excalibur.logger.LoggerManager;
 import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.activity.Initializable;
 import org.apache.avalon.framework.component.ComponentManager;
+import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
 import org.apache.avalon.framework.container.ContainerUtil;
@@ -45,6 +47,7 @@
 import org.apache.cocoon.util.IOUtils;
 import org.apache.cocoon.util.StringUtils;
 import org.apache.cocoon.util.log.CocoonLogFormatter;
+import org.apache.cocoon.util.log.Log4JConfigurator;
 
 import org.apache.commons.lang.BooleanUtils;
 import org.apache.commons.lang.SystemUtils;
@@ -55,6 +58,7 @@
 import org.apache.log.Hierarchy;
 import org.apache.log.Priority;
 import org.apache.log.util.DefaultErrorHandler;
+import org.apache.log4j.LogManager;
 
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
@@ -823,8 +827,15 @@
         defaultHierarchy.setDefaultLogTarget(servTarget);
         defaultHierarchy.setDefaultPriority(logPriority);
         final Logger logger = new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor(""));
-        final LogKitLoggerManager logKitLoggerManager = new LogKitLoggerManager(defaultHierarchy);
-        logKitLoggerManager.enableLogging(logger);
+        final String loggerManagerClass =
+            this.getInitParameter("logger-class", LogKitLoggerManager.class.getName());
+
+        // the log4j support requires currently that the log4j system is already configured
elsewhere
+
+        final LoggerManager loggerManager =
+                newLoggerManager(loggerManagerClass, defaultHierarchy);
+        ContainerUtil.enableLogging(loggerManager, logger);
+
         final DefaultContext subcontext = new DefaultContext(this.appContext);
         subcontext.put("portlet-context", this.portletContext);
         if (this.portletContextPath == null) {
@@ -839,9 +850,10 @@
         }
 
         try {
-            logKitLoggerManager.contextualize(subcontext);
-            this.loggerManager = logKitLoggerManager;
+            ContainerUtil.contextualize(loggerManager, subcontext);
+            this.loggerManager = loggerManager;
 
+            if (loggerManager instanceof Configurable) {
             //Configure the logkit management
             String logkitConfig = getInitParameter("logkit-config", "/WEB-INF/logkit.xconf");
 
@@ -856,15 +868,47 @@
             }
             final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
             final Configuration conf = builder.build(is);
-            logKitLoggerManager.configure(conf);
+                ContainerUtil.configure(loggerManager, conf);
+            }
+
+            // let's configure log4j
+            final String log4jConfig = getInitParameter("log4j-config", null);
+            if ( log4jConfig != null ) {
+                final Log4JConfigurator configurator = new Log4JConfigurator(subcontext);
+
+                // test if this is a qualified url
+                InputStream is = null;
+                if ( log4jConfig.indexOf(':') == -1) {
+                    is = this.portletContext.getResourceAsStream(log4jConfig);
+                    if (is == null) is = new FileInputStream(log4jConfig);
+                } else {
+                    final URL log4jURL = new URL(log4jConfig);
+                    is = log4jURL.openStream();
+                }
+                configurator.doConfigure(is, LogManager.getLoggerRepository());
+            }
+
+            ContainerUtil.initialize(loggerManager);
         } catch (Exception e) {
             errorHandler.error("Could not set up Cocoon Logger, will use screen instead",
e, null);
         }
 
-        if (accesslogger != null) {
-            this.log = logKitLoggerManager.getLoggerForCategory(accesslogger);
+        this.log = this.loggerManager.getLoggerForCategory(accesslogger);
+    }
+
+    private LoggerManager newLoggerManager(String loggerManagerClass, Hierarchy hierarchy)
{
+        if (loggerManagerClass.equals(LogKitLoggerManager.class.getName())) {
+            return new LogKitLoggerManager(hierarchy);
+        } else if (loggerManagerClass.equals(Log4JLoggerManager.class.getName()) ||
+                   loggerManagerClass.equalsIgnoreCase("LOG4J")) {
+            return new Log4JLoggerManager();
         } else {
-            this.log = logKitLoggerManager.getLoggerForCategory("cocoon");
+            try {
+                Class clazz = Class.forName(loggerManagerClass);
+                return (LoggerManager)clazz.newInstance();
+            } catch (Exception e) {
+                return new LogKitLoggerManager(hierarchy);
+            }
         }
     }
 

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/servlet/CocoonServlet.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/servlet/CocoonServlet.java	(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/servlet/CocoonServlet.java	Thu
Aug 12 06:10:49 2004
@@ -47,6 +47,7 @@
 import org.apache.cocoon.util.IOUtils;
 import org.apache.cocoon.util.StringUtils;
 import org.apache.cocoon.util.log.CocoonLogFormatter;
+import org.apache.cocoon.util.log.Log4JConfigurator;
 
 import org.apache.commons.lang.BooleanUtils;
 import org.apache.commons.lang.SystemUtils;
@@ -58,6 +59,7 @@
 import org.apache.log.Priority;
 import org.apache.log.output.ServletOutputLogTarget;
 import org.apache.log.util.DefaultErrorHandler;
+import org.apache.log4j.LogManager;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
@@ -824,8 +826,25 @@
                 final Configuration conf = builder.build(is);
                 ContainerUtil.configure(loggerManager, conf);
             }
-            ContainerUtil.initialize(loggerManager);
 
+            // let's configure log4j
+            final String log4jConfig = getInitParameter("log4j-config", null);
+            if ( log4jConfig != null ) {
+                final Log4JConfigurator configurator = new Log4JConfigurator(subcontext);
+
+                // test if this is a qualified url
+                InputStream is = null;
+                if ( log4jConfig.indexOf(':') == -1) {
+                    is = this.servletContext.getResourceAsStream(log4jConfig);
+                    if (is == null) is = new FileInputStream(log4jConfig);
+                } else {
+                    final URL log4jURL = new URL(log4jConfig);
+                    is = log4jURL.openStream();
+                }
+                configurator.doConfigure(is, LogManager.getLoggerRepository());
+            }
+
+            ContainerUtil.initialize(loggerManager);
         } catch (Exception e) {
             errorHandler.error("Could not set up Cocoon Logger, will use screen instead",
e, null);
         }

Modified: cocoon/branches/BRANCH_2_1_X/src/webapp/WEB-INF/web.xml
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/webapp/WEB-INF/web.xml	(original)
+++ cocoon/branches/BRANCH_2_1_X/src/webapp/WEB-INF/web.xml	Thu Aug 12 06:10:49 2004
@@ -131,9 +131,33 @@
     </init-param>
 
     <!--
+      This parameter switches the logging system from LogKit to Log4J for Cocoon.
+      Log4J has to be configured already.
+      <init-param>
+        <param-name>logger-class</param-name>
+        <param-value>org.apache.avalon.excalibur.logger.Log4JLoggerManager</param-value>
+      </init-param>
+    -->
+
+    <!--
+      If you want to configure log4j using Cocoon, then you can define
+      an XML configuration file here. You can use the usual log4j property
+      substituation mechanism, e.g. ${context-root} is replaced by the
+      context root of this web application etc.
+      You can configure the log4j configuration even if you use LogKit 
+      for Cocoon logging. You can use this to configure third party code
+      for example.
+      <init-param>
+        <param-name>log4j-config</param-name>
+        <param-value>/WEB-INF/log4j.xconf</param-value>
+      </init-param>
+    -->
+    
+    <!--
       Allow reinstantiating (reloading) of the cocoon instance. If this is
       set to "yes" or "true", a new cocoon instance can be created using
-      the request parameter "cocoon-reload". Default is no for security reasons.
+      the request parameter "cocoon-reload". It also enables that Cocoon is 
+      reloaded when cocoon.xconf changes. Default is no for security reasons.
     -->
     <init-param>
       <param-name>allow-reload</param-name>
@@ -280,7 +304,7 @@
       length header in the response. This is due to the internal processing
       of Readers and the Caching. So, this might be the reason if you get
       a warning about a wrong content length.
-      See http://nagoya.apache.org/bugzilla/show_bug.cgi?id=17370.
+      See http://issues.apache.org/bugzilla/show_bug.cgi?id=17370.
     <init-param>
       <param-name>show-time</param-name>
       <param-value>hide</param-value>
@@ -299,22 +323,20 @@
     <!--
        If true, Avalon Excalibur instrumentation will be enabled on all
        Instrumentable components with Cocoon and your Cocoon application.
-
+    -->
     <init-param>
       <param-name>enable-instrumentation</param-name>
-      <param-value>true</param-value>
+      <param-value>false</param-value>
     </init-param>
-    -->
 
     <!--
        This defines the location of the instrument manager configuration, only
        used if the init-param enable-instrumentation is enabled.
-
+    -->
     <init-param>
       <param-name>instrumentation-config</param-name>
       <param-value>/WEB-INF/instrumentation.xconf</param-value>
     </init-param>
-    -->
 
     <!--
       Set encoding used by the container. If not set the ISO-8859-1 encoding

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml	(original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml	Thu Aug 12 06:10:49 2004
@@ -213,6 +213,9 @@
      Portal: CocoonPortlet has new configuration parameter,
      default-session-scope.
    </action>
+   <action dev="CZ" type="add">
+     Add configuration support for log4j.
+   </action>
    <action dev="CZ" type="fix" fixes-bug="29373">
      Portal: Fix NPE when non-caching pipelines are used for the portal profile.
    </action>

Mime
View raw message