cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: cocoon-2.1/lib/core log4j-1.2.8.jar
Date Fri, 11 Jun 2004 20:29:29 GMT
cziegeler    2004/06/11 13:29:29

  Modified:    .        status.xml
               src/webapp/WEB-INF web.xml
               src/java/org/apache/cocoon/servlet CocoonServlet.java
               lib      jars.xml
  Added:       src/webapp/WEB-INF log4j.xconf
               src/java/org/apache/cocoon/util/log Log4JConfigurator.java
               lib/core log4j-1.2.8.jar
  Removed:     lib/optional log4j-1.2.8.jar
  Log:
  Add configuration support for log4j.
  
  Revision  Changes    Path
  1.364     +4 -1      cocoon-2.1/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/status.xml,v
  retrieving revision 1.363
  retrieving revision 1.364
  diff -u -r1.363 -r1.364
  --- status.xml	11 Jun 2004 12:05:48 -0000	1.363
  +++ status.xml	11 Jun 2004 20:29:29 -0000	1.364
  @@ -205,6 +205,9 @@
   
    <release version="@version@" date="@date@">
      <action dev="CZ" type="add">
  +     Add configuration support for log4j.
  +   </action>
  +   <action dev="CZ" type="add">
        Add profiling/debugging API for the sitemap.
      </action>
      <action dev="CZ" type="add">
  
  
  
  1.16      +13 -0     cocoon-2.1/src/webapp/WEB-INF/web.xml
  
  Index: web.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/webapp/WEB-INF/web.xml,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- web.xml	3 Jun 2004 12:31:30 -0000	1.15
  +++ web.xml	11 Jun 2004 20:29:29 -0000	1.16
  @@ -140,6 +140,19 @@
       -->
   
       <!--
  +      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.
  
  
  
  1.1                  cocoon-2.1/src/webapp/WEB-INF/log4j.xconf
  
  Index: log4j.xconf
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <!--
    Copyright 1999-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.
  -->
  <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
  
  <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
  
      <!-- This is a sample configuration for log4j.
           It simply just logs everything into a single
           log file.
           Note, that you can use properties for value substituation.
      -->
      <appender name="COCOON_DEFAULT" class="org.apache.log4j.FileAppender">
          <param name="File"   value="${context-root}/WEB-INF/logs/log4j.log" />
          <param name="Append" value="false" />	    	
          <layout class="org.apache.log4j.PatternLayout">
              <param name="ConversionPattern" value="%t %-5p %c{2} - %m%n"/>
          </layout>	    
      </appender>
  	
  	<root>
  	   <priority value ="debug" />
     	   <appender-ref ref="COCOON_DEFAULT" />
  	</root>
  	
  </log4j:configuration>
  
  
  
  1.30      +20 -1     cocoon-2.1/src/java/org/apache/cocoon/servlet/CocoonServlet.java
  
  Index: CocoonServlet.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/servlet/CocoonServlet.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- CocoonServlet.java	25 May 2004 07:28:26 -0000	1.29
  +++ CocoonServlet.java	11 Jun 2004 20:29:29 -0000	1.30
  @@ -76,6 +76,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.excalibur.instrument.InstrumentManager;
  @@ -87,6 +88,7 @@
   import org.apache.log.ErrorHandler;
   import org.apache.log.util.DefaultErrorHandler;
   import org.apache.log.output.ServletOutputLogTarget;
  +import org.apache.log4j.LogManager;
   
   /**
    * This is the entry point for Cocoon execution as an HTTP Servlet.
  @@ -825,6 +827,23 @@
                   final Configuration conf = builder.build(is);
                   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.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) {
  
  
  
  1.1                  cocoon-2.1/src/java/org/apache/cocoon/util/log/Log4JConfigurator.java
  
  Index: Log4JConfigurator.java
  ===================================================================
  /*
   * Created on 11.06.2004
   *
   * To change this generated comment go to 
   * Window>Preferences>Java>Code Generation>Code Template
   */
  /*
   * Copyright 1999-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.cocoon.util.log;
  
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.log4j.helpers.LogLog;
  import org.apache.log4j.xml.DOMConfigurator;
  
  /**
   * This is a configurator for log4j that supports variable substitution
   * 
   * @version CVS $Id: Log4JConfigurator.java,v 1.1 2004/06/11 20:29:29 cziegeler Exp $
   */
  public class Log4JConfigurator extends DOMConfigurator {
  
      protected Context context;
      
      public Log4JConfigurator(Context context) {
          this.context = context;
      }
      
      protected String subst(String value) {
          try {
            return this.substVars(value);
          } catch (IllegalArgumentException e) {
            LogLog.warn("Could not perform variable substitution.", e);
  
            return value;
          }
      }  
      
      static String DELIM_START = "${";
      static char   DELIM_STOP  = '}';
      static int DELIM_START_LEN = 2;
      static int DELIM_STOP_LEN  = 1;
  
      /**
       * This is directly copied from log4j's OptionConverter class.
       * The only difference is the getting of a property.
       */
      public String substVars(String val) 
      throws IllegalArgumentException {
  
          StringBuffer sbuf = new StringBuffer();
  
          int i = 0;
          int j, k;
  
          while(true) {
              j=val.indexOf(DELIM_START, i);
              if (j == -1) {
                  // no more variables
                  if(i==0) { // this is a simple string
                      return val;
                  } else { // add the tail string which contails no variables and return the
result.
                      sbuf.append(val.substring(i, val.length()));
                      return sbuf.toString();
                  }
              } else {
                  sbuf.append(val.substring(i, j));
                  k = val.indexOf(DELIM_STOP, j);
                  if(k == -1) {
                      throw new IllegalArgumentException('"'+val+
                               "\" has no closing brace. Opening brace at position " + j
                               + '.');
                  } else {
                      j += DELIM_START_LEN;
                      String key = val.substring(j, k);
                      // first try in System properties
                      String replacement = this.getSystemProperty(key);
                      // then try props parameter
                      if (replacement == null && this.context != null) {
                          try {
                              Object o = this.context.get(key);
                              if ( o != null ) {
                                  replacement = o.toString();
                              }
                          } catch (ContextException ce) {
                              LogLog.debug("Was not allowed to read context property \""+key+"\".");
                           
                          }
                      }
      
                      if (replacement != null) {
                          // Do variable substitution on the replacement string
                          // such that we can solve "Hello ${x2}" as "Hello p1" 
                          // the where the properties are
                          // x1=p1
                          // x2=${x1}
                          String recursiveReplacement = substVars(replacement);
                          sbuf.append(recursiveReplacement);
                      }
                      i = k + DELIM_STOP_LEN;
                  }
              }
          }
      }
      
      /**
       * This is directly copied from log4j's OptionConverter class.
       * The only difference is the getting of a property.
       */
      public String getSystemProperty(String key) {
          try {
              return System.getProperty(key, null);
          } catch(Throwable e) { // MS-Java throws com.ms.security.SecurityExceptionEx
              LogLog.debug("Was not allowed to read system property \""+key+"\".");
              return null;
          }
      }
  }
  
  
  
  1.226     +3 -3      cocoon-2.1/lib/jars.xml
  
  Index: jars.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/lib/jars.xml,v
  retrieving revision 1.225
  retrieving revision 1.226
  diff -u -r1.225 -r1.226
  --- jars.xml	7 Jun 2004 13:10:41 -0000	1.225
  +++ jars.xml	11 Jun 2004 20:29:29 -0000	1.226
  @@ -592,8 +592,8 @@
     <file>
       <title>Log4j</title>
       <description>Logging for java</description>
  -    <used-by>DELI (deli block)</used-by>
  -    <lib>optional/log4j-1.2.8.jar</lib>
  +    <used-by>Core and DELI (deli block)</used-by>
  +    <lib>core/log4j-1.2.8.jar</lib>
       <homepage>http://logging.apache.org/log4j/</homepage>
     </file>
   
  
  
  
  1.1                  cocoon-2.1/lib/core/log4j-1.2.8.jar
  
  	<<Binary file>>
  
  

Mime
View raw message