donaldp     2003/04/04 18:07:02

  Modified:    .        build.xml
               src/java/org/apache/avalon/phoenix/components/logger
                        DefaultLogManager.java
               src/test/org/apache/avalon/phoenix/components/logger/test
                        config3.xml
  Added:       src/java/org/apache/avalon/phoenix/components/logger
                        ExtendedLog4jLoggerManager.java
  Log:
  Support property expansion in Log4j configuration files.
  
  Fixes Issue PNIX-3
  
  Revision  Changes    Path
  1.233     +41 -1     avalon-phoenix/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/avalon-phoenix/build.xml,v
  retrieving revision 1.232
  retrieving revision 1.233
  diff -u -r1.232 -r1.233
  --- build.xml 4 Apr 2003 23:17:16 -0000       1.232
  +++ build.xml 5 Apr 2003 02:07:02 -0000       1.233
  @@ -105,6 +105,10 @@
       <!-- Invoke 'ant get-cli' to get these -->
       <property name="cli.jar" value="${repo.dir}/cli/cli-1.0/cli-1.0.jar"/>
   
  +    <!-- Invoke ant get-configkit' to get these -->
  +    <property name="configkit.jar" 
value="${repo.dir}/spice-configkit/spice-configkit-1.1/spice-configkit-1.1.jar"/>
  +    <fileset id="configkit.fileset" 
dir="${repo.dir}/spice-configkit/spice-configkit-1.1/lib"/>
  +
       <path id="project.class.path">
           <pathelement location="${xerces.jar}"/>
           <pathelement location="${framework.jar}"/>
  @@ -112,6 +116,7 @@
           <pathelement location="${wrapper.jar}"/>
           <pathelement path="${log4j.jar}"/>
           <pathelement path="${cli.jar}"/>
  +        <pathelement path="${configkit.jar}"/>
           <pathelement path="${mx4j.jar}"/>
           <pathelement path="${mx4j-tools.jar}"/>
           <pathelement path="${beanshell.jar}"/>
  @@ -431,6 +436,37 @@
           <untar src="${repo.dir}/cli/cli.tar" dest="${repo.dir}/cli"/>
       </target>
   
  +    <!-- =================================================================== -->
  +    <!-- ConfigKit Tasks.                                                    -->
  +    <!-- =================================================================== -->
  +    <target name="check-configkit-init" depends="init">
  +        <available property="configkit.present" 
classname="org.realityforge.configkit.PropertyExpander">
  +            <classpath refid="project.class.path"/>
  +        </available>
  +    </target>
  +
  +    <target name="check-configkit" depends="check-configkit-init" 
unless="configkit.present">
  +        <echo>********************************</echo>
  +        <echo>* Please execute target        *</echo>
  +        <echo>* 'get-configkit' in the main  *</echo>
  +        <echo>* build.xml build file         *</echo>
  +        <echo>* to download one and          *</echo>
  +        <echo>* a half Mb of Spice ConfigKit *</echo>
  +        <echo>********************************</echo>
  +        <fail message="Spice ConfigKit needed. See above."/>
  +    </target>
  +
  +    <!-- Get the jars from the configkit project. -->
  +    <target name="get-configkit" description="Get the Spice ConfigKit distribution 
from SourceForge.">
  +        <mkdir dir="${repo.dir}/spice-configkit"/>
  +        <get 
src="http://osdn.dl.sourceforge.net/sourceforge/spice/configkit-1.1.tar.gz";
  +            dest="${repo.dir}/spice-configkit/spice-configkit.tar.gz"
  +            verbose="true"
  +            usetimestamp="true"/>
  +        <gunzip src="${repo.dir}/spice-configkit/spice-configkit.tar.gz" 
dest="${repo.dir}/spice-configkit"/>
  +        <untar src="${repo.dir}/spice-configkit/spice-configkit.tar" 
dest="${repo.dir}/spice-configkit"/>
  +    </target>
  +
       <!-- Main target -->
       <target name="main" depends="dist-lite"
           description="generates the Phoenix distribution without the javadocs"/>
  @@ -451,7 +487,7 @@
   
   
       <!-- Check requirements of environment -->
  -    <target name="check-environment" depends="check-mx4j, check-log4j, check-cli, 
check-wrapper">
  +    <target name="check-environment" depends="check-mx4j, check-log4j, check-cli, 
check-configkit, check-wrapper">
           <available property="xerces.present" type="file" file="${xerces.jar}"/>
           <available property="servlet.present" classname="javax.servlet.Servlet">
               <classpath refid="project.class.path"/>
  @@ -817,6 +853,10 @@
           <zip destfile="${target.lib}/mx4j-tools.jar" basedir="${target.mx}"/>
   
           <copy file="${cli.jar}" todir="${bin.dist.bin}/lib"/>
  +        <copy file="${configkit.jar}" todir="${bin.dist.bin}/lib"/>
  +        <copy todir="${bin.dist.bin}/lib">
  +            <fileset refid="configkit.fileset"/>
  +        </copy>
           <copy file="${mx4j.jar}" todir="${bin.dist.bin}/lib"/>
           <copy file="${target.lib}/mx4j-tools.jar" todir="${bin.dist.bin}/lib"/>
   
  
  
  
  1.32      +2 -1      
avalon-phoenix/src/java/org/apache/avalon/phoenix/components/logger/DefaultLogManager.java
  
  Index: DefaultLogManager.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/components/logger/DefaultLogManager.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- DefaultLogManager.java    22 Mar 2003 12:07:10 -0000      1.31
  +++ DefaultLogManager.java    5 Apr 2003 02:07:02 -0000       1.32
  @@ -94,7 +94,7 @@
        * Constant used to define LogManager class to use log4j log format and system.
        */
       private static final String VERSION_LOG4J =
  -        "org.apache.avalon.excalibur.logger.Log4JConfLoggerManager";
  +        "org.apache.avalon.phoenix.components.logger.ExtendedLog4jLoggerManager";
   
       /**
        * Hold the value of phoenix.home
  @@ -141,6 +141,7 @@
           ContainerUtil.enableLogging( loggerManager, getLogger() );
           ContainerUtil.contextualize( loggerManager, createLoggerManagerContext( 
context ) );
           ContainerUtil.configure( loggerManager, logs );
  +        ContainerUtil.initialize( loggerManager );
           return loggerManager.getDefaultLogger();
       }
   
  
  
  
  1.1                  
avalon-phoenix/src/java/org/apache/avalon/phoenix/components/logger/ExtendedLog4jLoggerManager.java
  
  Index: ExtendedLog4jLoggerManager.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1997-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Avalon", "Phoenix" and "Apache Software Foundation"
      must  not be  used to  endorse or  promote products derived  from this
      software without prior written permission. For written permission, please
      contact [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.avalon.phoenix.components.logger;
  
  import org.apache.avalon.excalibur.logger.Log4JLoggerManager;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.ConfigurationUtil;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.phoenix.BlockContext;
  import org.apache.log4j.xml.DOMConfigurator;
  import org.w3c.dom.Element;
  import org.w3c.dom.Document;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.Node;
  import org.realityforge.configkit.PropertyExpander;
  import java.util.Map;
  import java.util.HashMap;
  
  /**
   * A LoggerManager for Log4j that will configure the Log4j subsystem
   * using specified configuration.
   *
   * @author <a href="mailto:Ole.Bulbuk at ebp.de">Ole Bulbuk</a>
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2003/04/05 02:07:02 $
   */
  public class ExtendedLog4jLoggerManager
      extends Log4JLoggerManager
      implements Contextualizable, Configurable, Initializable
  {
      private final PropertyExpander m_expander = new PropertyExpander();
      private final Map m_data = new HashMap();
      private Element m_element;
  
      public void contextualize( Context context )
          throws ContextException
      {
          extractData( context, BlockContext.APP_HOME_DIR );
          extractData( context, BlockContext.APP_NAME );
          //extractData( context, "phoenix.home" );
      }
  
      private void extractData( Context context, final String key ) throws 
ContextException
      {
          m_data.put( key, context.get( key ) );
      }
  
      public void configure( final Configuration configuration )
          throws ConfigurationException
      {
          m_element = ConfigurationUtil.toElement( configuration );
      }
  
      public void initialize()
          throws Exception
      {
          m_expander.expandValues( m_element, m_data );
          final Document document = m_element.getOwnerDocument();
          final Element newElement = document.createElement( "log4j:configuration" );
          final NodeList childNodes = m_element.getChildNodes();
          final int length = childNodes.getLength();
          for( int i = 0; i < length; i++ )
          {
              final Node node = childNodes.item( i );
              final Node newNode = node.cloneNode( true );
              newElement.appendChild( newNode );
          }
  
          document.appendChild( newElement );
          DOMConfigurator.configure( newElement );
      }
  }
  
  
  
  
  1.3       +2 -2      
avalon-phoenix/src/test/org/apache/avalon/phoenix/components/logger/test/config3.xml
  
  Index: config3.xml
  ===================================================================
  RCS file: 
/home/cvs/avalon-phoenix/src/test/org/apache/avalon/phoenix/components/logger/test/config3.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- config3.xml       16 Mar 2003 11:02:00 -0000      1.2
  +++ config3.xml       5 Apr 2003 02:07:02 -0000       1.3
  @@ -1,7 +1,7 @@
   <logs version="log4j">
   
       <appender name="DEFAULT" class="org.apache.log4j.FileAppender">
  -        <param name="File" value="test/test3/logs/default.log"/>
  +        <param name="File" value="${app.home}/logs/default.log"/>
           <param name="Append" value="false"/>
           <layout class="org.apache.log4j.PatternLayout">
               <param name="ConversionPattern"
  @@ -10,7 +10,7 @@
       </appender>
   
       <appender name="MYBLOCK_FILE" class="org.apache.log4j.FileAppender">
  -        <param name="File" value="test/test3/logs/myBlock.log"/>
  +        <param name="File" value="${app.home}/logs/myBlock.log"/>
           <param name="Append" value="false"/>
           <layout class="org.apache.log4j.PatternLayout">
               <param name="ConversionPattern"
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to