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-phoenix/src/java/org/apache/avalon/phoenix/frontends CLIMain.java
Date Mon, 04 Feb 2002 09:57:55 GMT
donaldp     02/02/04 01:57:55

  Modified:    src/java/org/apache/avalon/phoenix/components/embeddor
                        DefaultEmbeddor.java
               src/java/org/apache/avalon/phoenix/frontends CLIMain.java
  Log:
  Create the Logger in the Frontend rather than in the Embeddor. Creating it in the Embeddor
violates IOC.
  
  This also fixes a recently introduced bug ;)
  
  Revision  Changes    Path
  1.44      +0 -43     jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/embeddor/DefaultEmbeddor.java
  
  Index: DefaultEmbeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/embeddor/DefaultEmbeddor.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- DefaultEmbeddor.java	2 Feb 2002 11:50:10 -0000	1.43
  +++ DefaultEmbeddor.java	4 Feb 2002 09:57:55 -0000	1.44
  @@ -28,9 +28,6 @@
   import org.apache.avalon.framework.context.ContextException;
   import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -import org.apache.avalon.framework.logger.AvalonFormatter;
  -import org.apache.avalon.framework.logger.LogKitLogger;
  -import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.framework.parameters.ParameterException;
   import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.parameters.Parameters;
  @@ -45,10 +42,6 @@
   import org.apache.avalon.phoenix.interfaces.LogManager;
   import org.apache.avalon.phoenix.interfaces.PackageRepository;
   import org.apache.avalon.phoenix.interfaces.SystemManager;
  -import org.apache.log.Hierarchy;
  -import org.apache.log.LogTarget;
  -import org.apache.log.Priority;
  -import org.apache.log.output.io.FileTarget;
   
   /**
    * This is the object that is interacted with to create, manage and
  @@ -64,12 +57,8 @@
       private static final Resources REZ =
           ResourceManager.getPackageResources( DefaultEmbeddor.class );
   
  -    private static final String DEFAULT_LOG_FILE = "/logs/phoenix.log";
       private static final String DEFAULT_APPS_PATH = "/apps";
   
  -    private final static String DEFAULT_FORMAT =
  -        "%{time} [%7.7{priority}] (%{category}): %{message}\\n%{throwable}";
  -
       private EmbeddorObservable m_observable = new EmbeddorObservable();
       private Parameters m_parameters;
       private String m_phoenixHome;
  @@ -377,9 +366,6 @@
       private synchronized void createComponents()
           throws Exception
       {
  -        final Logger logger = createLogger();
  -        enableLogging( logger );
  -
           String component = null;
   
           component = m_parameters.getParameter( PackageRepository.ROLE );
  @@ -405,35 +391,6 @@
   
           component = m_parameters.getParameter( Kernel.ROLE );
           m_kernel = (Kernel)createComponent( component, Kernel.class );
  -    }
  -
  -    /**
  -     * Uses <code>org.apache.log.Hierarchy</code> to create a new
  -     * logger using "Phoenix" as its category, DEBUG as its
  -     * priority and the log-destination from Parameters as its
  -     * destination.
  -     * TODO: allow configurable priorities and multiple
  -     * logtargets.
  -     */
  -    private Logger createLogger()
  -        throws Exception
  -    {
  -        final String logDestination =
  -            m_parameters.getParameter( "log-destination", m_phoenixHome + DEFAULT_LOG_FILE
);
  -        final String logPriority =
  -            m_parameters.getParameter( "log-priority", "INFO" );
  -        final AvalonFormatter formatter = new AvalonFormatter( DEFAULT_FORMAT );
  -        final File file = new File( logDestination );
  -        final FileTarget logTarget = new FileTarget( file, false, formatter );
  -
  -        //Create an anonymous hierarchy so no other
  -        //components can get access to logging hierarchy
  -        final Hierarchy hierarchy = new Hierarchy();
  -        final org.apache.log.Logger logger = hierarchy.getLoggerFor( "Phoenix" );
  -        logger.setLogTargets( new LogTarget[]{ logTarget } );
  -        logger.setPriority( Priority.getPriorityForName( logPriority ) );
  -        logger.info( "Logger started" );
  -        return new LogKitLogger( logger );
       }
   
       /**
  
  
  
  1.20      +54 -0     jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/frontends/CLIMain.java
  
  Index: CLIMain.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/frontends/CLIMain.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- CLIMain.java	15 Dec 2001 22:51:34 -0000	1.19
  +++ CLIMain.java	4 Feb 2002 09:57:55 -0000	1.20
  @@ -13,10 +13,20 @@
   import org.apache.avalon.framework.context.DefaultContext;
   import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.avalon.framework.logger.AvalonFormatter;
  +import org.apache.avalon.framework.logger.LogKitLogger;
  +import org.apache.avalon.framework.logger.Logger;
  +import org.apache.avalon.framework.logger.LogEnabled;
   import org.apache.avalon.phoenix.Constants;
   import org.apache.avalon.phoenix.components.embeddor.DefaultEmbeddor;
   import org.apache.avalon.phoenix.interfaces.Embeddor;
   import java.util.Hashtable;
  +import java.io.File;
  +import org.apache.log.Hierarchy;
  +import org.apache.log.LogTarget;
  +import org.apache.log.Priority;
  +import org.apache.log.output.io.FileTarget;
   
   /**
    * The class to load the kernel and start it running.
  @@ -30,6 +40,13 @@
       private static final Resources REZ =
           ResourceManager.getPackageResources( CLIMain.class );
   
  +    private static final String DEFAULT_LOG_FILE = "/logs/phoenix.log";
  +
  +    private final static String DEFAULT_FORMAT =
  +        "%{time} [%7.7{priority}] (%{category}): %{message}\\n%{throwable}";
  +
  +
  +
       ///The embeddor attached to frontend
       private Embeddor m_embeddor;
   
  @@ -137,6 +154,12 @@
           {
               m_embeddor = new DefaultEmbeddor();
   
  +            if( m_embeddor instanceof LogEnabled )
  +            {
  +                final Logger logger = createLogger( parameters );
  +                ( (LogEnabled)m_embeddor ).enableLogging( logger );
  +            }
  +
               if( m_embeddor instanceof Contextualizable )
               {
                   final DefaultContext context = new DefaultContext( data );
  @@ -157,6 +180,37 @@
           }
   
           return true;
  +    }
  +
  +
  +    /**
  +     * Uses <code>org.apache.log.Hierarchy</code> to create a new
  +     * logger using "Phoenix" as its category, DEBUG as its
  +     * priority and the log-destination from Parameters as its
  +     * destination.
  +     * TODO: allow configurable priorities and multiple
  +     * logtargets.
  +     */
  +    private Logger createLogger( final Parameters parameters )
  +        throws Exception
  +    {
  +        final String phoenixHome = parameters.getParameter( "phoenix.home" );
  +        final String logDestination =
  +            parameters.getParameter( "log-destination", phoenixHome + DEFAULT_LOG_FILE
);
  +        final String logPriority =
  +            parameters.getParameter( "log-priority", "INFO" );
  +        final AvalonFormatter formatter = new AvalonFormatter( DEFAULT_FORMAT );
  +        final File file = new File( logDestination );
  +        final FileTarget logTarget = new FileTarget( file, false, formatter );
  +
  +        //Create an anonymous hierarchy so no other
  +        //components can get access to logging hierarchy
  +        final Hierarchy hierarchy = new Hierarchy();
  +        final org.apache.log.Logger logger = hierarchy.getLoggerFor( "Phoenix" );
  +        logger.setLogTargets( new LogTarget[]{ logTarget } );
  +        logger.setPriority( Priority.getPriorityForName( logPriority ) );
  +        logger.info( "Logger started" );
  +        return new LogKitLogger( logger );
       }
   
       /**
  
  
  

--
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