ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/frontends BasicLogger.java CLIMain.java
Date Tue, 12 Mar 2002 09:10:33 GMT
donaldp     02/03/12 01:10:33

  Modified:    proposal/myrmidon/src/java/org/apache/myrmidon/frontends
                        CLIMain.java
  Added:       proposal/myrmidon/src/java/org/apache/myrmidon/frontends
                        BasicLogger.java
  Log:
  Make LogKit an optional part not required by default frontend. Replace it with a basic console
logger instead
  
  Revision  Changes    Path
  1.29      +27 -40    jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/frontends/CLIMain.java
  
  Index: CLIMain.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/frontends/CLIMain.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- CLIMain.java	9 Mar 2002 10:13:03 -0000	1.28
  +++ CLIMain.java	12 Mar 2002 09:10:32 -0000	1.29
  @@ -21,14 +21,7 @@
   import org.apache.avalon.framework.CascadingException;
   import org.apache.avalon.framework.ExceptionUtil;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -import org.apache.avalon.framework.logger.LogKitLogger;
   import org.apache.avalon.framework.parameters.Parameters;
  -import org.apache.log.Hierarchy;
  -import org.apache.log.LogTarget;
  -import org.apache.log.Logger;
  -import org.apache.log.Priority;
  -import org.apache.log.format.PatternFormatter;
  -import org.apache.log.output.io.StreamTarget;
   import org.apache.myrmidon.Constants;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.interfaces.embeddor.Embeddor;
  @@ -43,7 +36,7 @@
    * to run project.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.28 $ $Date: 2002/03/09 10:13:03 $
  + * @version $Revision: 1.29 $ $Date: 2002/03/12 09:10:32 $
    */
   public class CLIMain
       extends AbstractLogEnabled
  @@ -52,7 +45,6 @@
           ResourceManager.getPackageResources( CLIMain.class );
   
       private final String DEFAULT_EMBEDDOR_CLASS = "org.apache.myrmidon.components.embeddor.DefaultEmbeddor";
  -    private final static String PATTERN = "[%8.8{category}] %{message}\\n%{throwable}";
   
       //defines for the Command Line options
       private final static int HELP_OPT = 'h';
  @@ -107,7 +99,8 @@
       private boolean m_dryRun = false;
   
       ///Log level to use
  -    private static Priority m_priority = Priority.WARN;
  +    //private static Priority m_priority = Priority.WARN;
  +    private static int m_priority = BasicLogger.LEVEL_WARN;
   
       /**
        * Main entry point called to run standard Myrmidon.
  @@ -259,10 +252,10 @@
                       m_priority = mapLogLevel( option.getArgument() );
                       break;
                   case VERBOSE_OPT:
  -                    m_priority = Priority.INFO;
  +                    m_priority = BasicLogger.LEVEL_INFO;
                       break;
                   case QUIET_OPT:
  -                    m_priority = Priority.ERROR;
  +                    m_priority = BasicLogger.LEVEL_ERROR;
                       break;
   
                   case INCREMENTAL_OPT:
  @@ -401,7 +394,6 @@
               {
                   break;
               }
  -
           }
       }
   
  @@ -412,7 +404,7 @@
       {
           // Build the message
           final String message;
  -        if( m_priority.isLowerOrEqual( Priority.INFO ) )
  +        if( m_priority <= BasicLogger.LEVEL_INFO )
           {
               // Verbose mode - include the stack traces
               message = ExceptionUtil.printStackTrace( throwable, 5, true, true );
  @@ -494,7 +486,8 @@
       private void prepareLogging() throws Exception
       {
           //handle logging...
  -        enableLogging( new LogKitLogger( createLogger( m_priority ) ) );
  +        final BasicLogger logger = new BasicLogger( "myrmidon", m_priority );
  +        enableLogging( logger );
       }
   
       private void shutdownEmbeddor( final Embeddor embeddor )
  @@ -562,36 +555,30 @@
       /**
        * Sets the log level.
        */
  -    private Priority mapLogLevel( final String logLevel ) throws Exception
  +    private int mapLogLevel( final String logLevel )
  +        throws Exception
       {
           final String logLevelCapitalized = logLevel.toUpperCase();
  -        final Priority priority = Priority.getPriorityForName( logLevelCapitalized );
  -        if( !priority.getName().equals( logLevelCapitalized ) )
  +        if( "DEBUG".equals( logLevelCapitalized ) )
  +        {
  +            return BasicLogger.LEVEL_DEBUG;
  +        }
  +        else if( "INFO".equals( logLevelCapitalized ) )
  +        {
  +            return BasicLogger.LEVEL_INFO;
  +        }
  +        else if( "WARN".equals( logLevelCapitalized ) )
  +        {
  +            return BasicLogger.LEVEL_WARN;
  +        }
  +        else if( "ERROR".equals( logLevelCapitalized ) )
  +        {
  +            return BasicLogger.LEVEL_ERROR;
  +        }
  +        else
           {
               final String message = REZ.getString( "bad-loglevel.error", logLevel );
               throw new Exception( message );
           }
  -        return priority;
  -    }
  -
  -    /**
  -     * Create Logger of appropriate log-level.
  -     *
  -     * @param priority the log-level
  -     * @return the logger
  -     * @exception Exception if an error occurs
  -     */
  -    private Logger createLogger( final Priority priority )
  -        throws Exception
  -    {
  -        final Logger logger = Hierarchy.getDefaultHierarchy().getLoggerFor( "myrmidon"
);
  -
  -        final PatternFormatter formatter = new PatternFormatter( PATTERN );
  -        final StreamTarget target = new StreamTarget( System.out, formatter );
  -        logger.setLogTargets( new LogTarget[]{target} );
  -
  -        logger.setPriority( priority );
  -
  -        return logger;
       }
   }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/frontends/BasicLogger.java
  
  Index: BasicLogger.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.myrmidon.frontends;
  
  import org.apache.avalon.framework.ExceptionUtil;
  import org.apache.avalon.framework.logger.Logger;
  
  /**
   * A basic logger that just prints out messages to <code>System.out</code>.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/03/12 09:10:33 $
   */
  class BasicLogger
      implements Logger
  {
      public final static int LEVEL_DEBUG = 0;
      public final static int LEVEL_INFO = 1;
      public final static int LEVEL_WARN = 2;
      public final static int LEVEL_ERROR = 3;
      public final static int LEVEL_FATAL = 4;
  
      /**
       * The string prefixed to all log messages.
       */
      private final String m_prefix;
  
      /**
       * The level at which messages start becoming logged.
       */
      private final int m_logLevel;
  
      /**
       * Create a logger that has specified prefix and is logging
       * at specified level.
       */
      public BasicLogger( final String prefix, final int logLevel )
      {
          m_prefix = prefix;
          m_logLevel = logLevel;
      }
  
      /**
       * Log a debug message.
       *
       * @param message the message
       */
      public void debug( final String message )
      {
          if( isDebugEnabled() )
          {
              output( message, null );
          }
      }
  
      /**
       * Log a debug message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public void debug( final String message, final Throwable throwable )
      {
          if( isDebugEnabled() )
          {
              output( message, throwable );
          }
      }
  
      /**
       * Determine if messages of priority "debug" will be logged.
       *
       * @return true if "debug" messages will be logged
       */
      public boolean isDebugEnabled()
      {
          return m_logLevel <= LEVEL_DEBUG;
      }
  
      /**
       * Log a info message.
       *
       * @param message the message
       */
      public void info( final String message )
      {
          if( isInfoEnabled() )
          {
              output( message, null );
          }
      }
  
      /**
       * Log a info message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public void info( final String message, final Throwable throwable )
      {
          if( isInfoEnabled() )
          {
              output( message, throwable );
          }
      }
  
      /**
       * Determine if messages of priority "info" will be logged.
       *
       * @return true if "info" messages will be logged
       */
      public boolean isInfoEnabled()
      {
          return m_logLevel <= LEVEL_INFO;
      }
  
      /**
       * Log a warn message.
       *
       * @param message the message
       */
      public void warn( final String message )
      {
          if( isWarnEnabled() )
          {
              output( message, null );
          }
      }
  
      /**
       * Log a warn message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public void warn( final String message, final Throwable throwable )
      {
          if( isWarnEnabled() )
          {
              output( message, throwable );
          }
      }
  
      /**
       * Determine if messages of priority "warn" will be logged.
       *
       * @return true if "warn" messages will be logged
       */
      public boolean isWarnEnabled()
      {
          return m_logLevel <= LEVEL_WARN;
      }
  
      /**
       * Log a error message.
       *
       * @param message the message
       */
      public void error( final String message )
      {
          if( isErrorEnabled() )
          {
              output( message, null );
          }
      }
  
      /**
       * Log a error message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public void error( final String message, final Throwable throwable )
      {
          if( isErrorEnabled() )
          {
              output( message, throwable );
          }
      }
  
      /**
       * Determine if messages of priority "error" will be logged.
       *
       * @return true if "error" messages will be logged
       */
      public boolean isErrorEnabled()
      {
          return m_logLevel <= LEVEL_ERROR;
      }
  
      /**
       * Log a fatalError message.
       *
       * @param message the message
       */
      public void fatalError( final String message )
      {
          if( isFatalErrorEnabled() )
          {
              output( message, null );
          }
      }
  
      /**
       * Log a fatalError message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public void fatalError( final String message, final Throwable throwable )
      {
          if( isFatalErrorEnabled() )
          {
              output( message, throwable );
          }
      }
  
      /**
       * Determine if messages of priority "fatalError" will be logged.
       *
       * @return true if "fatalError" messages will be logged
       */
      public boolean isFatalErrorEnabled()
      {
          return m_logLevel <= LEVEL_FATAL;
      }
  
      /**
       * Create a new child logger.
       * The name of the child logger is [current-loggers-name].[passed-in-name]
       *
       * @param name the subname of this logger
       * @return the new logger
       * @exception IllegalArgumentException if name has an empty element name
       */
      public Logger getChildLogger( final String name )
      {
          return new BasicLogger( m_prefix + "." + name, m_logLevel );
      }
  
      /**
       * Utility method to output messages.
       */
      private void output( final String message, final Throwable throwable )
      {
          final StringBuffer sb = new StringBuffer( m_prefix );
          if( null != message )
          {
              sb.append( message );
          }
  
          if( null != throwable )
          {
              final String stackTrace = ExceptionUtil.printStackTrace( throwable, 8, true,
true );
              sb.append( stackTrace );
          }
  
          System.out.println( sb.toString() );
      }
  }
  
  
  

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


Mime
View raw message