You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2003/04/17 01:03:53 UTC

cvs commit: avalon-logkit/src/java/org/apache/log/util LogKit2AvalonLoggerAdapter.java LogKitAvalonLogger.java

donaldp     2003/04/16 16:03:52

  Modified:    .        build.xml check-targets.ent
                        check-targets.properties
  Added:       src/java/org/apache/log/util LogKit2AvalonLoggerAdapter.java
                        LogKitAvalonLogger.java
  Log:
  Add in Logger facade for Avalon also add in utility class that helps adapt between LogKit and Logger hierarchys
  
  Revision  Changes    Path
  1.100     +4 -9      avalon-logkit/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/avalon-logkit/build.xml,v
  retrieving revision 1.99
  retrieving revision 1.100
  diff -u -r1.99 -r1.100
  --- build.xml	12 Mar 2003 11:32:44 -0000	1.99
  +++ build.xml	16 Apr 2003 23:03:51 -0000	1.100
  @@ -102,6 +102,7 @@
       <pathelement path="${jdbc.jar}" />
       <pathelement path="${jms.jar}" />
       <pathelement path="${log4j.jar}" />
  +    <pathelement path="${avalon-framework.jar}"/>
       <fileset dir="${lib.dir}">
         <include name="*.jar" />
       </fileset>
  @@ -127,6 +128,7 @@
                      jms-check,
                      junit-check,
                      log4j-check,
  +                   framework-check,
                      servletapi-check"/>
   
     <!-- defer to check-targets.ent for downloading dependencies -->
  @@ -157,13 +159,6 @@
       <echo message=""/>
     </target>
   
  -  <target name="help" depends="usage"/>
  -
  -  <!-- Set up dist properties -->
  -  <target name="setup-properties" >
  -
  -  </target>
  -
     <target name="import-avalon-site" description="Imports the avalon-site" depends="import-log4j">
       <!-- these are really old releases. Need to verify we can get the
            latest of everything and just download that! -->
  @@ -245,7 +240,7 @@
   
     <!-- Prepares the build directory -->
     <target name="compile"
  -          depends="setup-properties,setup-dependencies,prepare"
  +          depends="setup-dependencies,prepare"
             description="Compile project">
   
   
  @@ -639,7 +634,7 @@
     </target>
   
     <!-- Create the announcements and HEADER.html -->
  -  <target name="announcement" depends="setup-properties">
  +  <target name="announcement">
   
       <filter token="Name" value="${Name}"/>
       <filter token="name" value="${name}"/>
  
  
  
  1.3       +29 -5     avalon-logkit/check-targets.ent
  
  Index: check-targets.ent
  ===================================================================
  RCS file: /home/cvs/avalon-logkit/check-targets.ent,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- check-targets.ent	21 Feb 2003 05:52:02 -0000	1.2
  +++ check-targets.ent	16 Apr 2003 23:03:52 -0000	1.3
  @@ -48,9 +48,12 @@
     <!-- Set up properties -->
     <property file="check-targets.properties"/>
     <target name="setup-dependencies">
  +    <available property="framework.present"
  +               classname="org.apache.avalon.framework.logger.Logger"
  +               classpathref="project.class.path" />
       <available property="bsf.present"
                  classname="com.ibm.bsf.BSFEngine"
  -               classpathref="project.class.path" />
  +               classpathref="project.class.path"/>
       <available property="checkstyle.present"
                  classname="com.puppycrawl.tools.checkstyle.Checker"
                  classpathref="project.class.path" />
  @@ -99,9 +102,9 @@
       Run the build target import-${id} and it will download
       the needed jar - you should be online for that.
       - OR -
  -    Set the ${id}.jar property in the ant.properties file 
  +    Set the ${id}.jar property in the ant.properties file
       to the full path of the jar.
  -    
  +
       If you have a fast connection you can also just run the build target
       import-all-auto-dependencies, which will download all external jars this
       buildfile knows about.
  @@ -125,7 +128,7 @@
       ${dist.url}
       and place it in ${lib.dir}.
       - OR -
  -    Set the ${id}.jar property in the ant.properties file 
  +    Set the ${id}.jar property in the ant.properties file
       to the full path of the jar.
   
       Please note that ${id} is licensed under the ${license}
  @@ -168,11 +171,32 @@
     </target>
   
     <target name="check-all-dependencies"
  -          depends="bsf-check,checkstyle-check,javamail-check,jdbc-check,jms-check,junit-check,log4j-check,logkit-check,servletapi-check,commons-logging-check"
  +          depends="bsf-check,checkstyle-check,javamail-check,jdbc-check,jms-check,junit-check,log4j-check,logkit-check,servletapi-check,framework-check,commons-logging-check"
         description="checks for all dependencies we know about. This is usually more than the minimum needed to build this project; actual use is not recommended."/>
     <target name="import-all-auto-dependencies"
             depends="import-bsf,import-checkstyle,import-junit,import-log4j,import-logkit,import-commons-logging"
         description="checks for all dependencies we know about. This is usually more than the minimum needed to build this project; actual use is not recommended."/>
  +
  +<!-- BSF -->
  +  <target name="framework-check" unless="framework.present" depends="setup-dependencies">
  +    <antcall target="missing-dependency">
  +        <param name="id" value="${framework.id}"/>
  +        <param name="jar.id" value="${framework.id}"/>
  +        <param name="version" value="${framework.version}"/>
  +        <param name="license" value="${framework.license}"/>
  +        <param name="license.url" value="${framework.license.url}"/>
  +    </antcall>
  +  </target>
  +
  +  <target name="import-framework" depends="setup-dependencies">
  +    <antcall target="import-dependency">
  +        <param name="id" value="${framework.id}"/>
  +        <param name="jar.id" value="${framework.id}"/>
  +        <param name="version" value="${framework.version}"/>
  +        <param name="license" value="${framework.license}"/>
  +        <param name="license.url" value="${framework.license.url}"/>
  +    </antcall>
  +  </target>
   
     <!-- BSF -->
     <target name="bsf-check" unless="bsf.present" depends="setup-dependencies">
  
  
  
  1.3       +8 -1      avalon-logkit/check-targets.properties
  
  Index: check-targets.properties
  ===================================================================
  RCS file: /home/cvs/avalon-logkit/check-targets.properties,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- check-targets.properties	21 Feb 2003 05:52:02 -0000	1.2
  +++ check-targets.properties	16 Apr 2003 23:03:52 -0000	1.3
  @@ -7,12 +7,19 @@
   cpl.license=Common Public License
   cpl.license.url=http://www.opensource.org/licenses/cpl.php
   asl.license=Apache Software License
  -asl.license.url=http://www.opensource.org/licenses/apachepl.php
  +asl.license.url=http://www.apache.org/LICENSE
   lgpl.license=GNU Lesser General Public License
   lgpl.license.url=http://www.opensource.org/licenses/lgpl-license.php
   sbcl.license=Sun Binary Code License
   npl.license=Netscape Public License
   npl.license.url=http://www.mozilla.org/MPL/NPL-1.1.html
  +
  +# Framework
  +framework.version=4.1.4
  +framework.id=avalon-framework
  +framework.license=${asl.license}
  +framework.license.url=${asl.license.url}
  +framework.dist.url=http://avalon.apache.org
   
   # BSF
   bsf.version=2.2
  
  
  
  1.1                  avalon-logkit/src/java/org/apache/log/util/LogKit2AvalonLoggerAdapter.java
  
  Index: LogKit2AvalonLoggerAdapter.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
   * modification, 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 "Jakarta", "Avalon", 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 apache@apache.org.
   *
   * 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 (INCLUDING, 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.log.util;
  
  import org.apache.log.Hierarchy;
  import org.apache.log.LogEvent;
  import org.apache.log.LogTarget;
  import org.apache.log.Priority;
  import org.apache.avalon.framework.logger.Logger;
  
  /**
   * A basic adapter that adapts an Avalon Logger to a Logkit Logger.
   * Useful when providing backwards compatability support for Loggable
   * components.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/04/16 23:03:52 $
   * @since 4.1.4
   */
  public final class LogKit2AvalonLoggerAdapter
      implements LogTarget
  {
      /**
       * The Avalon Logger that we re-route to.
       */
      private final Logger m_logger;
  
      /**
       * Create a Logkit {@link org.apache.log.Logger} instance that
       * redirects to an Avalon {@link Logger} instance.
       *
       * @param logger the Avalon Logger
       * @return the LogKit Logger
       */
      public static org.apache.log.Logger createLogger( final Logger logger )
      {
          final Hierarchy hierarchy = new Hierarchy();
          final org.apache.log.Logger logKitLogger = hierarchy.getLoggerFor( "" );
          final LogKit2AvalonLoggerAdapter target =
              new LogKit2AvalonLoggerAdapter( logger );
          logKitLogger.setLogTargets( new LogTarget[ ] { target } );
          return logKitLogger;
      }
  
      /**
       * Constructor for an Adaptor. Adapts to
       * specified Avalon Logger.
       *
       * @param logger the avalon logger.
       */
      public LogKit2AvalonLoggerAdapter( final Logger logger )
      {
          if( null == logger )
          {
              throw new NullPointerException( "logger" );
          }
          m_logger = logger;
      }
  
      /**
       * Route a LogKit message to an avalon Logger.
       *
       * @param event the log message
       */
      public void processEvent( LogEvent event )
      {
          final String message = event.getMessage();
          final Throwable throwable = event.getThrowable();
          final Priority priority = event.getPriority();
          if( Priority.DEBUG == priority )
          {
              m_logger.debug( message, throwable );
          }
          else if( Priority.INFO == priority )
          {
              m_logger.info( message, throwable );
          }
          else if( Priority.WARN == priority )
          {
              m_logger.warn( message, throwable );
          }
          else if( Priority.ERROR == priority )
          {
              m_logger.error( message, throwable );
          }
          else
          {
              m_logger.fatalError( message, throwable );
          }
      }
  }
  
  
  
  1.1                  avalon-logkit/src/java/org/apache/log/util/LogKitAvalonLogger.java
  
  Index: LogKitAvalonLogger.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
   * modification, 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 "Jakarta", "Avalon", 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 apache@apache.org.
   *
   * 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 (INCLUDING, 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.log.util;
  
  import org.apache.avalon.framework.logger.Logger;
  
  /**
   * The default LogKit wrapper class for Logger.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/04/16 23:03:52 $
   */
  public final class LogKitAvalonLogger
      implements Logger
  {
      //underlying implementation to delegate to
      private final org.apache.log.Logger m_logger;
  
      /**
       * Create a logger that delegates to specified logger.
       *
       * @param logger the LogKit logger to delegate to
       */
      public LogKitAvalonLogger( org.apache.log.Logger logger )
      {
          if( null == logger )
          {
              throw new NullPointerException( "logger" );
          }
          m_logger = logger;
      }
  
      /**
       * Log a debug message.
       *
       * @param message the message
       */
      public final void debug( final String message )
      {
          m_logger.debug( message );
      }
  
      /**
       * Log a debug message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public final void debug( final String message, final Throwable throwable )
      {
          m_logger.debug( message, throwable );
      }
  
      /**
       * Determine if messages of priority "debug" will be logged.
       *
       * @return true if "debug" messages will be logged
       */
      public final boolean isDebugEnabled()
      {
          return m_logger.isDebugEnabled();
      }
  
      /**
       * Log a info message.
       *
       * @param message the message
       */
      public final void info( final String message )
      {
          m_logger.info( message );
      }
  
      /**
       * Log a info message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public final void info( final String message, final Throwable throwable )
      {
          m_logger.info( message, throwable );
      }
  
      /**
       * Determine if messages of priority "info" will be logged.
       *
       * @return true if "info" messages will be logged
       */
      public final boolean isInfoEnabled()
      {
          return m_logger.isInfoEnabled();
      }
  
      /**
       * Log a warn message.
       *
       * @param message the message
       */
      public final void warn( final String message )
      {
          m_logger.warn( message );
      }
  
      /**
       * Log a warn message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public final void warn( final String message, final Throwable throwable )
      {
          m_logger.warn( message, throwable );
      }
  
      /**
       * Determine if messages of priority "warn" will be logged.
       *
       * @return true if "warn" messages will be logged
       */
      public final boolean isWarnEnabled()
      {
          return m_logger.isWarnEnabled();
      }
  
      /**
       * Log a error message.
       *
       * @param message the message
       */
      public final void error( final String message )
      {
          m_logger.error( message );
      }
  
      /**
       * Log a error message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public final void error( final String message, final Throwable throwable )
      {
          m_logger.error( message, throwable );
      }
  
      /**
       * Determine if messages of priority "error" will be logged.
       *
       * @return true if "error" messages will be logged
       */
      public final boolean isErrorEnabled()
      {
          return m_logger.isErrorEnabled();
      }
  
      /**
       * Log a fatalError message.
       *
       * @param message the message
       */
      public final void fatalError( final String message )
      {
          m_logger.fatalError( message );
      }
  
      /**
       * Log a fatalError message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public final void fatalError( final String message, final Throwable throwable )
      {
          m_logger.fatalError( message, throwable );
      }
  
      /**
       * Determine if messages of priority "fatalError" will be logged.
       *
       * @return true if "fatalError" messages will be logged
       */
      public final boolean isFatalErrorEnabled()
      {
          return m_logger.isFatalErrorEnabled();
      }
  
      /**
       * Create a new child logger.
       * The name of the child logger is [current-loggers-name].[passed-in-name]
       * Throws <code>IllegalArgumentException</code> if name has an empty element name
       *
       * @param name the subname of this logger
       * @return the new logger
       */
      public final Logger getChildLogger( final String name )
      {
          return new LogKitAvalonLogger( m_logger.getChildLogger( name ) );
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org