avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler LogKit2LoggerTarget.java ComponentFactory.java
Date Sun, 10 Nov 2002 00:35:31 GMT
donaldp     2002/11/09 16:35:31

  Modified:    fortress/src/java/org/apache/excalibur/fortress/handler
                        ComponentFactory.java
  Added:       fortress/src/java/org/apache/excalibur/fortress/handler
                        LogKit2LoggerTarget.java
  Log:
  Support Loggable lifecycle interface as it seems some people are still using it ;(
  
  Revision  Changes    Path
  1.32      +29 -8     jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ComponentFactory.java
  
  Index: ComponentFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ComponentFactory.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- ComponentFactory.java	9 Nov 2002 23:25:44 -0000	1.31
  +++ ComponentFactory.java	10 Nov 2002 00:35:31 -0000	1.32
  @@ -56,6 +56,7 @@
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.logger.LogEnabled;
   import org.apache.avalon.framework.logger.Logger;
  +import org.apache.avalon.framework.logger.Loggable;
   import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.framework.service.ServiceManager;
  @@ -163,18 +164,38 @@
                               m_componentClass.getName() + "." );
           }
   
  -        if( component instanceof LogEnabled )
  +        if( component instanceof LogEnabled ||
  +            component instanceof Loggable )
           {
  -            final String logger = ( m_configuration == null ? null : m_configuration.getAttribute(
"logger", null ) );
  -            if( null == logger )
  +            Logger logger;
  +            final String name = ( m_configuration == null ? null : m_configuration.getAttribute(
"name", null ) );
  +            if( null == name )
               {
  -                if( m_logger.isDebugEnabled() ) m_logger.debug( "no logger attribute available,
using standard logger" );
  -                ContainerUtil.enableLogging( component, m_logManager.getDefaultLogger()
);
  +                if( m_logger.isDebugEnabled() ) m_logger.debug( "no name attribute available,
using standard name" );
  +                logger = m_logManager.getDefaultLogger();
               }
               else
               {
  -                if( m_logger.isDebugEnabled() ) m_logger.debug( "logger attribute is "
+ logger );
  -                ContainerUtil.enableLogging( component, m_logManager.getLoggerForCategory(
logger ) );
  +                if( m_logger.isDebugEnabled() ) m_logger.debug( "name attribute is " +
name );
  +                logger = m_logManager.getLoggerForCategory( name );
  +            }
  +
  +            if( component instanceof LogEnabled )
  +            {
  +                ContainerUtil.enableLogging( component, logger );
  +            }
  +            else
  +            {
  +                final String message = "WARNING: " + m_componentClass.getName() +
  +                    " implements the Loggable lifecycle stage. This is " +
  +                    " a deprecated feature that will be removed in the future. " +
  +                    " Please upgrade to using LogEnabled.";
  +                m_logger.warn( message );
  +                System.out.println( message );
  +
  +                final org.apache.log.Logger logkitLogger =
  +                    LogKit2LoggerTarget.createLogger( logger );
  +                ((Loggable)component).setLogger( logkitLogger );
               }
           }
   
  
  
  
  1.1                  jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/LogKit2LoggerTarget.java
  
  Index: LogKit2LoggerTarget.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.fortress.handler;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.log.Hierarchy;
  import org.apache.log.LogEvent;
  import org.apache.log.LogTarget;
  import org.apache.log.Priority;
  
  /**
   * A basic LogKit target that routes from LogKit to
   * Avalon Logger.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/11/10 00:35:31 $
   */
  class LogKit2LoggerTarget
      implements LogTarget
  {
      private final Logger m_logger;
  
      static org.apache.log.Logger createLogger( final Logger logger )
      {
          final Hierarchy hierarchy = new Hierarchy();
          final org.apache.log.Logger logKitLogger = hierarchy.getLoggerFor( "" );
          final LogKit2LoggerTarget target =
              new LogKit2LoggerTarget( logger );
          logKitLogger.setLogTargets( new LogTarget[ ] { target } );
          return logKitLogger;
      }
  
      LogKit2LoggerTarget( final Logger logger )
      {
          if( null == logger )
          {
              throw new NullPointerException( "logger" );
          }
          m_logger = logger;
      }
  
      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 );
          }
      }
  }
  
  
  

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


Mime
View raw message