mcconnell    2004/01/28 22:11:34

  Modified:    merlin/logging/logkit/api project.xml
               merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit
                        DefaultLoggingFactory.java
               
merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory
                        PluginTargetFactory.java Resources.properties
  Added:       merlin/logging/logkit/api/src/java/org/apache/avalon/logging/logkit
                        LogTargetFactoryBuilder.java
               merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit
                        DefaultLogTargetFactoryBuilder.java
               
merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory
                        package.html
               merlin/logging/logkit/plugins/datagram .cvsignore maven.xml
                        project.properties project.xml
               
merlin/logging/logkit/plugins/datagram/src/java/org/apache/avalon/logging/logkit/factory/datagram
                        DatagramTargetFactory.java Resources.properties
                        package.html
               merlin/logging/logkit/plugins/socket .cvsignore maven.xml
                        project.properties project.xml
               
merlin/logging/logkit/plugins/socket/src/java/org/apache/avalon/logging/logkit/factory/socket
                        Resources.properties SocketTargetFactory.java
                        package.html
  Removed:     merlin/logging/logkit/datagram .cvsignore maven.xml
                        project.properties project.xml
               
merlin/logging/logkit/datagram/src/java/org/apache/avalon/logging/logkit/factory
                        DatagramTargetFactory.java Resources.properties
               
merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory
                        SocketTargetFactory.java
  Log:
  Seperate out mainstream logging targets from supplimentary, improve the log target 
factory creation semantics and consolidate log target builder functionality.
  
  Revision  Changes    Path
  1.2       +10 -0     avalon/merlin/logging/logkit/api/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/logging/logkit/api/project.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- project.xml       24 Jan 2004 23:25:32 -0000      1.1
  +++ project.xml       29 Jan 2004 06:11:33 -0000      1.2
  @@ -29,6 +29,16 @@
         <artifactId>avalon-framework-api</artifactId>
         <version>4.1.5</version>
       </dependency>
  +    <dependency>
  +      <groupId>avalon-repository</groupId>
  +      <artifactId>avalon-repository-api</artifactId>
  +      <version>1.3-SNAPSHOT</version>
  +    </dependency>
  +    <dependency>
  +      <groupId>avalon-repository</groupId>
  +      <artifactId>avalon-repository-spi</artifactId>
  +      <version>1.3-SNAPSHOT</version>
  +    </dependency>
     </dependencies>
   
   </project>
  
  
  
  1.1                  
avalon/merlin/logging/logkit/api/src/java/org/apache/avalon/logging/logkit/LogTargetFactoryBuilder.java
  
  Index: LogTargetFactoryBuilder.java
  ===================================================================
  /* 
   * Copyright 2004 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.avalon.logging.logkit;
  
  import java.io.File;
  
  import org.apache.avalon.framework.logger.Logger;
  
  import org.apache.avalon.logging.provider.LoggingException;
  
  import org.apache.avalon.repository.provider.InitialContext;
  import org.apache.avalon.repository.provider.Factory;
  
  /**
   * A LogTargetFactoryBuilder provides support for the establishment of 
   * new logging targets.
   */
  public interface LogTargetFactoryBuilder
  {
     /**
      * Build a log target factory using a supplied class.  The implementation
      * checks the first available constructor arguments and builds a set of 
      * arguments based on the arguments supplied to this builder instance.
      *
      * @param clazz the log target factory class
      * @return a instance of the class
      * @exception LoggingException if the class does not expose a public 
      *    constructor, or the constructor requires arguments that the 
      *    builder cannot resolve, or if a unexpected instantiation error 
      *    ooccurs
      */ 
      public LogTargetFactory buildLogTargetFactory( Class clazz ) 
        throws LoggingException;
  }
  
  
  1.7       +7 -104    
avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/DefaultLoggingFactory.java
  
  Index: DefaultLoggingFactory.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/DefaultLoggingFactory.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DefaultLoggingFactory.java        28 Jan 2004 14:42:16 -0000      1.6
  +++ DefaultLoggingFactory.java        29 Jan 2004 06:11:33 -0000      1.7
  @@ -85,6 +85,7 @@
       private File m_basedir;
       private LogTargetFactoryManager m_factories;
       private LogTargetManager m_targets;
  +    private LogTargetFactoryBuilder m_builder;
   
       //--------------------------------------------------------------------------
       // constructor
  @@ -157,12 +158,10 @@
           Map targetsMap = new HashMap();
           m_targets = new DefaultLogTargetManager( targetsMap );
   
  -        //
  -        // setup the logging target factories
  -        //
  -
  -        //final Configuration factoriesConfig = config.getChild( "factories" );
  -        //setupTargetFactories( factoriesMap, factoriesConfig );
  +        m_builder = 
  +          new DefaultLogTargetFactoryBuilder( 
  +            m_context, m_classloader, m_logger, m_basedir, 
  +            m_factories, m_targets );
   
           //
           // setup the logging targets
  @@ -254,6 +253,7 @@
               {
                   final String error = 
                     REZ.getString( "target.notice.fail", id );
  +                m_logger.error( error, e );
                   throw new LoggingException( error, e );
               }
           }
  @@ -286,7 +286,7 @@
           {
               Class clazz = getLogTargetFactoryClass( key );
               LogTargetFactory newFactory = 
  -              buildLogTargetFactoryViaConstructor( clazz );
  +              m_builder.buildLogTargetFactory( clazz );
               factories.put( key, newFactory );
               return newFactory;
           }
  @@ -351,103 +351,6 @@
                   "target.error.missing-id", 
                   listing );
               throw new LoggingException( error );
  -        }
  -    }
  -
  -    private LogTargetFactory buildLogTargetFactoryViaConstructor( Class clazz ) 
  -      throws LoggingException
  -    {
  -        Constructor[] constructors = clazz.getConstructors();
  -        if( constructors.length < 1 ) 
  -        {
  -            final String error = 
  -              REZ.getString( 
  -                "factory.error.no-constructor", 
  -                clazz.getName() );
  -            throw new LoggingException( error );
  -        }
  -
  -        //
  -        // log target factories only have one constructor
  -        //
  -
  -        Constructor constructor = constructors[0];
  -        Class[] classes = constructor.getParameterTypes();
  -        Object[] args = new Object[ classes.length ];
  -        for( int i=0; i<classes.length; i++ )
  -        {
  -            Class c = classes[i];
  -            if( File.class.isAssignableFrom( c ) )
  -            {
  -                args[i] = m_basedir;
  -            }
  -            else if( Logger.class.isAssignableFrom( c ) )
  -            {
  -                args[i] = m_logger;
  -            }
  -            else if( LogTargetFactoryManager.class.isAssignableFrom( c ) )
  -            {
  -                args[i] = m_factories;
  -            }
  -            else if( LogTargetManager.class.isAssignableFrom( c ) )
  -            {
  -                args[i] = m_targets;
  -            }
  -            else if( FormatterFactory.class.isAssignableFrom( c ) )
  -            {
  -                args[i] = FORMATTER;
  -            }
  -            else if( ClassLoader.class.isAssignableFrom( c ) )
  -            {
  -                args[i] = m_classloader;
  -            }
  -            else if( InitialContext.class.isAssignableFrom( c ) )
  -            {
  -                args[i] = m_context;
  -            }
  -            else
  -            {
  -                final String error = 
  -                  REZ.getString( 
  -                    "factory.error.unrecognized-parameter", 
  -                    c.getName(),
  -                    clazz.getName() );
  -                throw new LoggingException( error );
  -            }
  -        }
  -
  -        //
  -        // instantiate the factory
  -        //
  -
  -        return instantiateLogTargetFactory( constructor, args );
  -    }
  -
  -   /**
  -    * Instantiation of a factory instance using a supplied constructor 
  -    * and arguments.
  -    * 
  -    * @param constructor the factory constructor
  -    * @param args the constructor arguments
  -    * @return the factory instance
  -    * @exception LoggingException if an instantiation error occurs
  -    */
  -    private LogTargetFactory instantiateLogTargetFactory( 
  -      Constructor constructor, Object[] args ) 
  -      throws LoggingException
  -    {
  -        Class clazz = constructor.getDeclaringClass();
  -        try
  -        {
  -            return (LogTargetFactory) constructor.newInstance( args );
  -        }
  -        catch( Throwable e )
  -        {
  -            final String error = 
  -              REZ.getString( 
  -                "target.error.instantiation", 
  -                clazz.getName() );
  -            throw new LoggingException( error, e );
           }
       }
   
  
  
  
  1.1                  
avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/DefaultLogTargetFactoryBuilder.java
  
  Index: DefaultLogTargetFactoryBuilder.java
  ===================================================================
  /* 
   * Copyright 2004 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.avalon.logging.logkit;
  
  import java.io.File;
  import java.util.Map;
  import java.util.HashMap;
  import java.util.ArrayList;
  
  import java.lang.reflect.Constructor;
  import java.lang.reflect.InvocationTargetException ;
  import java.lang.reflect.Method ;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.ConsoleLogger;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.DefaultConfiguration;
  import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  
  import org.apache.avalon.logging.provider.LoggingCriteria;
  import org.apache.avalon.logging.provider.LoggingException;
  import org.apache.avalon.logging.provider.LoggingManager;
  import org.apache.avalon.logging.data.CategoriesDirective;
  import org.apache.avalon.logging.data.CategoryDirective;
  import org.apache.avalon.logging.logkit.factory.FileTargetFactory;
  import org.apache.avalon.logging.logkit.factory.StreamTargetFactory;
  import org.apache.avalon.logging.logkit.factory.MulticastTargetFactory;
  import org.apache.avalon.logging.logkit.factory.PluginTargetFactory;
  
  import org.apache.avalon.repository.provider.InitialContext;
  import org.apache.avalon.repository.provider.Factory;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.excalibur.configuration.ConfigurationUtil;
  
  import org.apache.log.LogTarget;
  import org.apache.log.output.io.StreamTarget;
  import org.apache.log.format.Formatter;
  
  /**
   * The DefaultLoggingFactory provides support for the establishment of a 
   * new logging system using LogKit as the implementation.
   */
  public class DefaultLogTargetFactoryBuilder implements LogTargetFactoryBuilder
  {
      //--------------------------------------------------------------------------
      // static
      //--------------------------------------------------------------------------
  
      private static final Resources REZ =
        ResourceManager.getPackageResources( DefaultLogTargetFactoryBuilder.class );
  
      private static final FormatterFactory FORMATTER = 
        new DefaultFormatterFactory();
  
      //--------------------------------------------------------------------------
      // immutable state
      //--------------------------------------------------------------------------
  
      private final ClassLoader m_classloader;
      private final InitialContext m_context;
      private final Logger m_logger;
      private final File m_basedir;
      private final LogTargetFactoryManager m_factories;
      private final LogTargetManager m_targets;
      
      //--------------------------------------------------------------------------
      // constructor
      //--------------------------------------------------------------------------
  
     /**
      * Creation of a new default factory.
      * @param context the repository inital context
      * @param classloader the factory classloader
      */
      public DefaultLogTargetFactoryBuilder( 
        InitialContext context, ClassLoader classloader, Logger logger, File basedir, 
        LogTargetFactoryManager factories, LogTargetManager targets )
      {
          m_context = context;
          m_classloader = classloader;
          m_logger = logger;
          m_basedir = basedir;
          m_factories = factories;
          m_targets = targets;
      }
  
      //--------------------------------------------------------------------------
      // implementation
      //--------------------------------------------------------------------------
  
     /**
      * Build a log target factory using a supplied class.  The implementation
      * checks the first available constructor arguments and builds a set of 
      * arguments based on the arguments supplied to this builder instance.
      *
      * @param clazz the log target factory class
      * @return a instance of the class
      * @exception LoggingException if the class does not expose a public 
      *    constructor, or the constructor requires arguments that the 
      *    builder cannot resolve, or if a unexpected instantiation error 
      *    ooccurs
      */ 
      public LogTargetFactory buildLogTargetFactory( Class clazz ) 
        throws LoggingException
      {
          Constructor[] constructors = clazz.getConstructors();
          if( constructors.length < 1 ) 
          {
              final String error = 
                REZ.getString( 
                  "factory.error.no-constructor", 
                  clazz.getName() );
              throw new LoggingException( error );
          }
  
          //
          // log target factories only have one constructor
          //
  
          Constructor constructor = constructors[0];
          Class[] classes = constructor.getParameterTypes();
          Object[] args = new Object[ classes.length ];
          for( int i=0; i<classes.length; i++ )
          {
              Class c = classes[i];
              if( File.class.isAssignableFrom( c ) )
              {
                  args[i] = m_basedir;
              }
              else if( Logger.class.isAssignableFrom( c ) )
              {
                  args[i] = m_logger;
              }
              else if( LogTargetFactoryManager.class.isAssignableFrom( c ) )
              {
                  args[i] = m_factories;
              }
              else if( LogTargetManager.class.isAssignableFrom( c ) )
              {
                  args[i] = m_targets;
              }
              else if( FormatterFactory.class.isAssignableFrom( c ) )
              {
                  args[i] = FORMATTER;
              }
              else if( ClassLoader.class.isAssignableFrom( c ) )
              {
                  args[i] = m_classloader;
              }
              else if( InitialContext.class.isAssignableFrom( c ) )
              {
                  args[i] = m_context;
              }
              else if( LogTargetFactoryBuilder.class.isAssignableFrom( c ) )
              {
                  args[i] = this;
              }
              else
              {
                  final String error = 
                    REZ.getString( 
                      "factory.error.unrecognized-parameter", 
                      c.getName(),
                      clazz.getName() );
                  throw new LoggingException( error );
              }
          }
  
          //
          // instantiate the factory
          //
  
          return instantiateLogTargetFactory( constructor, args );
      }
  
     /**
      * Instantiation of a factory instance using a supplied constructor 
      * and arguments.
      * 
      * @param constructor the factory constructor
      * @param args the constructor arguments
      * @return the factory instance
      * @exception LoggingException if an instantiation error occurs
      */
      private LogTargetFactory instantiateLogTargetFactory( 
        Constructor constructor, Object[] args ) 
        throws LoggingException
      {
          Class clazz = constructor.getDeclaringClass();
          try
          {
              return (LogTargetFactory) constructor.newInstance( args );
          }
          catch( Throwable e )
          {
              final String error = 
                REZ.getString( 
                  "target.error.instantiation", 
                  clazz.getName() );
              throw new LoggingException( error, e );
          }
      }
  }
  
  
  1.2       +23 -24    
avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory/PluginTargetFactory.java
  
  Index: PluginTargetFactory.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory/PluginTargetFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PluginTargetFactory.java  28 Jan 2004 14:44:35 -0000      1.1
  +++ PluginTargetFactory.java  29 Jan 2004 06:11:34 -0000      1.2
  @@ -31,6 +31,7 @@
   import org.apache.avalon.logging.logkit.LogTargetException;
   import org.apache.avalon.logging.logkit.LogTargetFactory;
   import org.apache.avalon.logging.logkit.LogTargetManager;
  +import org.apache.avalon.logging.logkit.LogTargetFactoryBuilder;
   
   import org.apache.avalon.repository.Artifact;
   import org.apache.avalon.repository.provider.InitialContext;
  @@ -63,14 +64,12 @@
       // immutable state
       //--------------------------------------------------------------
   
  +    private final LogTargetFactoryBuilder m_builder;
  +
       private final ClassLoader m_classloader;
  +
       private final InitialContext m_context;
  -    private final Logger m_logger;
  -    private final File m_basedir;
   
  -    //
  -    // table of factories keyed by artifact spec
  -    //
       private final Map m_factories = new HashMap();
   
       //--------------------------------------------------------------
  @@ -78,13 +77,11 @@
       //--------------------------------------------------------------
   
       public PluginTargetFactory( 
  -      InitialContext context, ClassLoader classloader, 
  -      Logger logger, File basedir )
  +      ClassLoader classloader, InitialContext context, LogTargetFactoryBuilder 
builder )
       {
  -        m_context = context;
  +        m_builder = builder;
           m_classloader = classloader;
  -        m_logger = logger;
  -        m_basedir = basedir;
  +        m_context = context;
       }
   
       //--------------------------------------------------------------
  @@ -99,8 +96,6 @@
       public LogTarget createTarget( final Configuration config )
           throws LogTargetException
       {
  -        String listing = ConfigurationUtil.list( config );
  -        m_logger.info( "## CONFIG: " + listing );
           final String spec = config.getAttribute( "artifact", null );
           if( null == spec )
           {
  @@ -109,30 +104,34 @@
               throw new LogTargetException( error );
           }
   
  -        LogTargetFactory factory = (LogTargetFactory) m_factories.get( spec );
  -        if( null != factory)
  +        LogTargetFactory factory = getLogTargetFactory( spec );
  +        return factory.createTarget( config );
  +    }
  +
  +    private LogTargetFactory getLogTargetFactory( String spec )
  +      throws LogTargetException
  +    {
  +        if( m_factories.containsKey( spec ) )
           {
  -            return factory.createTarget( config );
  +            return (LogTargetFactory) m_factories.get( spec );
           }
   
           //
           // otherwise we need to construct the factory, register it
           // under the spec key and return it to the client
           //
  -
  +        
           try
           {
               final String uri = "artifact:" + spec;
               Artifact artifact = Artifact.createArtifact( uri );
  -            Builder builder = m_context.newBuilder( m_classloader, artifact );
  -            factory = (LogTargetFactory) builder.getFactory();
  -
  -            //
  -            // to do - add factory parameterization
  -            //
  -
  +            Builder builder = 
  +              m_context.newBuilder( m_classloader, artifact );
  +            Class clazz = builder.getFactoryClass();
  +            LogTargetFactory factory = 
  +              m_builder.buildLogTargetFactory( clazz );
               m_factories.put( spec, factory );
  -            return factory.createTarget( config );
  +            return factory;
           }
           catch( Throwable e )
           {
  
  
  
  1.4       +0 -12     
avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: 
/home/cvs/avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory/Resources.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Resources.properties      28 Jan 2004 14:42:17 -0000      1.3
  +++ Resources.properties      29 Jan 2004 06:11:34 -0000      1.4
  @@ -1,20 +1,8 @@
  -datagram.error.missing-address=Missing 'address' attribute is supplied datagram 
target configuration.
  -datagram.error.unknown-host=Datagram target references an unknown host.
  -datagram.error.missing-host=Datagram target does not contain required 'hostname' 
attribute.
  -datagram.error.internal=Internal error while attempting to construct datagram 
target.
  -datagram.error.missing-port=Datagram target does not contain required 'port' 
attribute.
  -
   file.error.missing-rotation=Missing file rotation strategy element.  The file 
target must contain a single rotation strategy child element named 
[or|size|date|interval|time].
   file.error.logkit-rotation=LogKit error while attempting to construct rotating file 
target.
   file.error.io=IOException while attempting to construct file target.
   file.error.config=File target configuration error.
   file.error.internal=Internal error while attempting to construct file log target.
  -
  -socket.error.missing-address=Missing 'address' attribute is supplied socket target 
configuration.
  -socket.error.unknown-host=Socket target references an unknown host.
  -socket.error.missing-host=Socket target does not contain required 'hostname' 
attribute.
  -socket.error.missing-port=Socket target does not contain required 'port' attribute.
  -socket.error.internal=Internal error while attempting to construct socket target.
   
   multicast.error.unknown-id=Multicast targetref references an unknown log target id 
[{0}].
   multicast.error.missing-id=Multicast targetref 'id' attribute is missing.
  
  
  
  1.1                  
avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory/package.html
  
  Index: package.html
  ===================================================================
  <body>
  <p>The <code>factory</code> package contains a set of standard logging targets 
including a rotating file log target, a serial target (suitable for console logging), 
and a multicast target used for redirecting log event to multiple targets.</p>
  </body>
  
  
  
  1.1                  avalon/merlin/logging/logkit/plugins/datagram/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  maven.log
  velocity.log
  build.properties
  target
  .classpath
  .project
  
  
  
  1.1                  avalon/merlin/logging/logkit/plugins/datagram/maven.xml
  
  Index: maven.xml
  ===================================================================
  <project default="jar:install" xmlns:maven="jelly:maven" xmlns:j="jelly:core" 
xmlns:util="jelly:util" xmlns:ant="jelly:ant">
  
    <postGoal name="java:prepare-filesystem">
      <attainGoal name="avalon:artifact"/>
    </postGoal>
  
    <postGoal name="jar:install">
      <ant:copy verbose="yes"
         toDir="${maven.repo.local}/${pom.groupId}/jars" 
         file="${maven.build.dir}/${pom.artifactId}-${pom.currentVersion}.jar.meta" />
    </postGoal>
  
  </project>
  
  
  
  1.1                  avalon/merlin/logging/logkit/plugins/datagram/project.properties
  
  Index: project.properties
  ===================================================================
  #
  # factory class
  #
  
  avalon.artifact.factory = 
org.apache.avalon.logging.logkit.factory.datagram.DatagramTargetFactory
  
  
  
  
  
  1.1                  avalon/merlin/logging/logkit/plugins/datagram/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <project>
  
    <extend>${basedir}/../../../../project.xml</extend>
  
    <groupId>avalon-logging</groupId>
    <id>avalon-logkit-datagram</id>
    <name>Avalon Logging Logkit Datagram Target</name>
    <package>org.apache.avalon.logging.logkit</package>
    <currentVersion>1.0-SNAPSHOT</currentVersion>
  
    <inceptionYear>2002</inceptionYear>
    <shortDescription>Avalon Logging Logkit Datagram Target</shortDescription>
  
    <dependencies>
  
      <!-- avalon dependecies -->
  
      <dependency>
        <groupId>avalon-repository</groupId>
        <artifactId>avalon-repository-main</artifactId>
        <version>1.3-SNAPSHOT</version>
      </dependency>
  
      <dependency>
        <groupId>avalon-logging</groupId>
        <artifactId>avalon-logging-api</artifactId>
        <version>1.0-SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>avalon-logging</groupId>
        <artifactId>avalon-logkit-api</artifactId>
        <version>1.0-SNAPSHOT</version>
      </dependency>
  
      <dependency>
        <groupId>avalon-framework</groupId>
        <artifactId>avalon-framework-api</artifactId>
        <version>4.1.5</version>
      </dependency>
  
      <dependency>
        <id>excalibur-i18n</id>
        <version>1.1</version>
      </dependency>
  
      <dependency>
        <groupId>logkit</groupId>
        <artifactId>logkit</artifactId>
        <version>1.2.2</version>
      </dependency>
  
    </dependencies>
  </project>
  
  
  
  1.1                  
avalon/merlin/logging/logkit/plugins/datagram/src/java/org/apache/avalon/logging/logkit/factory/datagram/DatagramTargetFactory.java
  
  Index: DatagramTargetFactory.java
  ===================================================================
  /* 
   * Copyright 2004 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.avalon.logging.logkit.factory.datagram;
  
  import java.io.IOException;
  import java.net.InetAddress;
  import java.net.UnknownHostException;
  import java.util.Map;
  import java.util.HashMap;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.logging.logkit.LogTargetException;
  import org.apache.avalon.logging.logkit.LogTargetFactory;
  import org.apache.avalon.logging.logkit.FormatterFactory;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  
  import org.apache.log.LogTarget;
  import org.apache.log.format.ExtendedPatternFormatter;
  import org.apache.log.format.Formatter;
  import org.apache.log.format.PatternFormatter;
  import org.apache.log.format.RawFormatter;
  import org.apache.log.output.net.DatagramOutputTarget;
  
  /**
   * This factory creates LogTargets with a wrapped DatagramOutputTarget around it.
   * <p>
   * Configuration syntax:
   * <pre>
   * &lt;datagram-target id="target-id"&gt;
   *   &lt;address hostname="hostname" port="4455" /&gt;
   *   &lt;format type="extended"&gt;
   *      %7.7{priority} %23.23{time:yyyy-MM-dd HH:mm:ss:SSS} [%25.25{category}] : 
%{message}\n%{throwable}
   *   &lt;/format&gt;
   * &lt;/datagram-target&gt;
   * </pre>
   * </p>
   * <p>
   *  This factory creates a DatagramOutputTarget object which will
   *  sends datagrams to the specified address. The name of the target is specified by 
the hostname attribute
   *  of the &lt;address&gt; element and the port by the port attribute.The 
&lt;address&gt; element
   *  wraps the format to output the log.
   * </p>
   *
   *
   * @author <a href="mailto:[EMAIL PROTECTED]"> Rajendra Ghorpade </a>
   */
  public class DatagramTargetFactory implements LogTargetFactory
  {
      //--------------------------------------------------------------
      // static
      //--------------------------------------------------------------
  
      private static final Resources REZ =
        ResourceManager.getPackageResources( DatagramTargetFactory.class );
  
      //--------------------------------------------------------------
      // immutable state
      //--------------------------------------------------------------
  
      private final FormatterFactory m_formatter;
  
      //--------------------------------------------------------------
      // constructor
      //--------------------------------------------------------------
  
      public DatagramTargetFactory( FormatterFactory formatter )
      {
          m_formatter = formatter;
      }
  
      //--------------------------------------------------------------
      // LogTargetFactory
      //--------------------------------------------------------------
  
      /**
       * Create a LogTarget based on a supplied configuration
       * @param conf the target coonfiguration
       * @return the datagram target
       * @exception LogTargetException if a target creation error occurs
       */
      public LogTarget createTarget( final Configuration conf )
          throws LogTargetException
      {
          InetAddress address;
  
          final Configuration configChild = conf.getChild( "address", false );
          if( null == configChild )
          {
              final String error = 
                REZ.getString( "datagram.error.missing-address" );
              throw new LogTargetException( error );
          }
  
          try
          {
              address = 
                InetAddress.getByName( 
                  configChild.getAttribute( "hostname" ) );
          }
          catch( UnknownHostException uhex )
          {
              final String error = 
                REZ.getString( "datagram.error.unknown-host" );
              throw new LogTargetException( error, uhex );
          }
          catch( ConfigurationException e )
          {
              final String error = 
                REZ.getString( "datagram.error.missing-host" );
              throw new LogTargetException( error, e );
          }
  
          Configuration formatConfig = conf.getChild( "format" );
  
          final Formatter formatter = 
            m_formatter.createFormatter( formatConfig );
  
          try
          {
              int port = configChild.getAttributeAsInteger( "port" );
              return new DatagramOutputTarget( address, port, formatter );
          }
          catch( IOException ioex )
          {
              final String error = 
                REZ.getString( "datagram.error.internal" );
              throw new LogTargetException( error, ioex );
          }
          catch( ConfigurationException e )
          {
              final String error = 
                REZ.getString( "datagram.error.missing-port" );
              throw new LogTargetException( error, e );
          }
      }
  }
  
  
  
  
  1.1                  
avalon/merlin/logging/logkit/plugins/datagram/src/java/org/apache/avalon/logging/logkit/factory/datagram/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  datagram.error.missing-address=Missing 'address' attribute is supplied datagram 
target configuration.
  datagram.error.unknown-host=Datagram target references an unknown host.
  datagram.error.missing-host=Datagram target does not contain required 'hostname' 
attribute.
  datagram.error.internal=Internal error while attempting to construct datagram target.
  datagram.error.missing-port=Datagram target does not contain required 'port' 
attribute.
  
  
  
  1.1                  
avalon/merlin/logging/logkit/plugins/datagram/src/java/org/apache/avalon/logging/logkit/factory/datagram/package.html
  
  Index: package.html
  ===================================================================
  <body>
  <p>The <code>datagram</code> package contains a datagram plugin log target.</p>
  </body>
  
  
  
  1.1                  avalon/merlin/logging/logkit/plugins/socket/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  maven.log
  velocity.log
  build.properties
  target
  .classpath
  .project
  
  
  
  1.1                  avalon/merlin/logging/logkit/plugins/socket/maven.xml
  
  Index: maven.xml
  ===================================================================
  <project default="jar:install" xmlns:maven="jelly:maven" xmlns:j="jelly:core" 
xmlns:util="jelly:util" xmlns:ant="jelly:ant">
  
    <postGoal name="java:prepare-filesystem">
      <attainGoal name="avalon:artifact"/>
    </postGoal>
  
    <postGoal name="jar:install">
      <ant:copy verbose="yes"
         toDir="${maven.repo.local}/${pom.groupId}/jars" 
         file="${maven.build.dir}/${pom.artifactId}-${pom.currentVersion}.jar.meta" />
    </postGoal>
  
  </project>
  
  
  
  1.1                  avalon/merlin/logging/logkit/plugins/socket/project.properties
  
  Index: project.properties
  ===================================================================
  #
  # factory class
  #
  
  avalon.artifact.factory = 
org.apache.avalon.logging.logkit.factory.socket.SocketTargetFactory
  
  
  
  
  
  1.1                  avalon/merlin/logging/logkit/plugins/socket/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <project>
  
    <extend>${basedir}/../../../../project.xml</extend>
  
    <groupId>avalon-logging</groupId>
    <id>avalon-logkit-socket</id>
    <name>Avalon Logging Logkit Socket Target</name>
    <package>org.apache.avalon.logging.logkit</package>
    <currentVersion>1.0-SNAPSHOT</currentVersion>
  
    <inceptionYear>2002</inceptionYear>
    <shortDescription>Avalon Logging Logkit Socket Target</shortDescription>
  
    <dependencies>
  
      <!-- avalon dependecies -->
  
      <dependency>
        <groupId>avalon-repository</groupId>
        <artifactId>avalon-repository-main</artifactId>
        <version>1.3-SNAPSHOT</version>
      </dependency>
  
      <dependency>
        <groupId>avalon-logging</groupId>
        <artifactId>avalon-logging-api</artifactId>
        <version>1.0-SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>avalon-logging</groupId>
        <artifactId>avalon-logkit-api</artifactId>
        <version>1.0-SNAPSHOT</version>
      </dependency>
  
      <dependency>
        <groupId>avalon-framework</groupId>
        <artifactId>avalon-framework-api</artifactId>
        <version>4.1.5</version>
      </dependency>
  
      <dependency>
        <id>excalibur-i18n</id>
        <version>1.1</version>
      </dependency>
  
      <dependency>
        <groupId>logkit</groupId>
        <artifactId>logkit</artifactId>
        <version>1.2.2</version>
      </dependency>
  
    </dependencies>
  </project>
  
  
  
  1.1                  
avalon/merlin/logging/logkit/plugins/socket/src/java/org/apache/avalon/logging/logkit/factory/socket/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  socket.error.missing-address=Missing 'address' attribute is supplied socket target 
configuration.
  socket.error.unknown-host=Socket target references an unknown host.
  socket.error.missing-host=Socket target does not contain required 'hostname' 
attribute.
  socket.error.missing-port=Socket target does not contain required 'port' attribute.
  socket.error.internal=Internal error while attempting to construct socket target.
  
  
  
  
  1.1                  
avalon/merlin/logging/logkit/plugins/socket/src/java/org/apache/avalon/logging/logkit/factory/socket/SocketTargetFactory.java
  
  Index: SocketTargetFactory.java
  ===================================================================
  /* 
   * Copyright 2004 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.avalon.logging.logkit.factory.socket;
  
  import java.io.IOException;
  import java.net.InetAddress;
  import java.net.UnknownHostException;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  
  import org.apache.avalon.logging.logkit.LogTargetFactory;
  import org.apache.avalon.logging.logkit.LogTargetException;
  
  import org.apache.log.LogTarget;
  import org.apache.log.output.net.SocketOutputTarget;
  
  /**
   * This plugin factory creates LogTargets with a wrapped SocketOutputTarget around 
it.
   * <p>
   * Configuration syntax:
   * <pre>
   * &lt;socket-target id="target-id"&gt;
   *   &lt;address hostname="hostname" port="4455" /&gt;
   * &lt;/socket-target&gt;
   * </pre>
   * </p>
   * <p>
   *  This factory creates a SocketOutputTarget object which will
   *  TCP/IP socket to communicate with the server. The name of the target is 
specified by the
   *  hostname attribute of the &lt;address&gt; element and the port by the port 
attribute.
   *  In the config file above the formatting for the log messages is not embedded as 
it should
   *  be specified on the server side
   * </p>
   *
   *
   * @author <a href="mailto:[EMAIL PROTECTED]"> Rajendra Ghorpade </a>
   */
  public class SocketTargetFactory implements LogTargetFactory
  {
      //--------------------------------------------------------------
      // static
      //--------------------------------------------------------------
  
      private static final Resources REZ =
        ResourceManager.getPackageResources( SocketTargetFactory.class );
  
      //--------------------------------------------------------------
      // LogTargetFactory
      //--------------------------------------------------------------
  
      /**
       * Creates a log target based on Configuration
       *
       * @param conf Configuration requied for creating the log target
       * @throws ConfigurationException if something goes wrong while reading from
       *          configuration
       */
      public LogTarget createTarget( final Configuration conf )
          throws LogTargetException
      {
          final InetAddress address;
  
          final Configuration configChild = 
            conf.getChild( "address", false );
          if( null == configChild )
          {
              final String error = 
                REZ.getString( "socket.error.missing-address" );
              throw new LogTargetException( error );
          }
  
          try
          {
              address = 
                InetAddress.getByName( 
                  configChild.getAttribute( "hostname" ) );
          }
          catch( UnknownHostException uhex )
          {
              final String error = 
                REZ.getString( "socket.error.unknown-host" );
              throw new LogTargetException( error, uhex );
          }
          catch( ConfigurationException e )
          {
              final String error = 
                REZ.getString( "socket.error.missing-host" );
              throw new LogTargetException( error, e );
          }
  
          try
          {
              final int port = configChild.getAttributeAsInteger( "port" );
              return new SocketOutputTarget( address, port );
          }
          catch( ConfigurationException e )
          {
              final String error = 
                REZ.getString( "socket.error.missing-port" );
              throw new LogTargetException( error, e );
          }
          catch( Throwable e )
          {
              final String error = 
                REZ.getString( "socket.error.internal" );
              throw new LogTargetException( error, e );
          }
      }
  }
  
  
  
  1.1                  
avalon/merlin/logging/logkit/plugins/socket/src/java/org/apache/avalon/logging/logkit/factory/socket/package.html
  
  Index: package.html
  ===================================================================
  <body>
  <p>The <code>socket</code> package contains a plugin socket log target.</p>
  </body>
  
  
  

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

Reply via email to