avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/frontends PhoenixServlet.java
Date Mon, 04 Feb 2002 10:11:59 GMT
colus       02/02/04 02:11:59

  Modified:    src/java/org/apache/avalon/phoenix/frontends
                        PhoenixServlet.java
  Log:
  Create the Logger in the Frontend rather than in the Embeddor.
  
  Revision  Changes    Path
  1.6       +45 -9     jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/frontends/PhoenixServlet.java
  
  Index: PhoenixServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/frontends/PhoenixServlet.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PhoenixServlet.java	11 Dec 2001 10:13:34 -0000	1.5
  +++ PhoenixServlet.java	4 Feb 2002 10:11:59 -0000	1.6
  @@ -7,17 +7,25 @@
    */
   package org.apache.avalon.phoenix.frontends;
   
  +import java.io.File;
   import javax.servlet.ServletContext;
   import javax.servlet.ServletException;
   import javax.servlet.http.HttpServlet;
  -import org.apache.avalon.excalibur.i18n.ResourceManager;
  -import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.framework.CascadingRuntimeException;
   import org.apache.avalon.framework.ExceptionUtil;
  +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.Parameterizable;
   import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.avalon.excalibur.i18n.ResourceManager;
  +import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.phoenix.components.embeddor.SingleAppEmbeddor;
   import org.apache.avalon.phoenix.interfaces.Embeddor;
  +import org.apache.log.Hierarchy;
  +import org.apache.log.LogTarget;
  +import org.apache.log.Priority;
  +import org.apache.log.output.io.FileTarget;
   
   /**
    * Servlet frontends for SingleAppEmbeddor.
  @@ -31,6 +39,11 @@
       private static final Resources REZ =
           ResourceManager.getPackageResources( PhoenixServlet.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}";
  +
       private Parameters m_parameters;
       private SingleAppEmbeddor m_embeddor;
   
  @@ -38,7 +51,7 @@
                                        final String defaultValue )
       {
           final String value = getInitParameter( name );
  -        if( null == value )
  +        if ( null == value )
           {
               return defaultValue;
           }
  @@ -55,11 +68,11 @@
   
           //TODO: configuring with more parameters.
           final ServletContext context = getServletContext();
  -        final String logDestination = 
  +        final String logDestination =
               context.getRealPath( getInitParameter( "log-destination", "/WEB-INF/logs/phoenix.log"
) );
           final String logPriority = getInitParameter( "log-priority", "INFO" );
           final String appName = getInitParameter( "application-name", "default" );
  -        final String appLoc = 
  +        final String appLoc =
               context.getRealPath( getInitParameter( "application-location", "/WEB-INF/"
+ appName ) );
   
           m_parameters = new Parameters();
  @@ -71,7 +84,8 @@
           try
           {
               m_embeddor = new SingleAppEmbeddor();
  -            if( m_embeddor instanceof Parameterizable )
  +            m_embeddor.enableLogging( createLogger( m_parameters ) );
  +            if ( m_embeddor instanceof Parameterizable )
               {
                   ( (Parameterizable)m_embeddor ).parameterize( m_parameters );
               }
  @@ -80,7 +94,7 @@
               final Thread thread = new Thread( this, "Phoenix" );
               thread.start();
           }
  -        catch( final Throwable throwable )
  +        catch ( final Throwable throwable )
           {
               log( REZ.getString( "main.exception.header" ) );
               log( "---------------------------------------------------------" );
  @@ -99,7 +113,7 @@
           {
               m_embeddor.execute();
           }
  -        catch( final Throwable throwable )
  +        catch ( final Throwable throwable )
           {
               log( REZ.getString( "main.exception.header" ) );
               log( "---------------------------------------------------------" );
  @@ -122,7 +136,7 @@
               m_embeddor = null;
               m_parameters = null;
           }
  -        catch( final Throwable throwable )
  +        catch ( final Throwable throwable )
           {
               log( REZ.getString( "main.exception.header" ) );
               log( "---------------------------------------------------------" );
  @@ -130,5 +144,27 @@
               log( "---------------------------------------------------------" );
               log( REZ.getString( "main.exception.footer" ) );
           }
  +    }
  +
  +    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