You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by ep...@apache.org on 2004/02/18 15:38:56 UTC

cvs commit: jakarta-turbine-3/src/java/org/apache/turbine Turbine.java TurbineConstants.java

epugh       2004/02/18 06:38:56

  Modified:    src/java/org/apache/turbine Turbine.java
                        TurbineConstants.java
  Log:
  port of T2.x log file loading.
  
  Revision  Changes    Path
  1.48      +40 -36    jakarta-turbine-3/src/java/org/apache/turbine/Turbine.java
  
  Index: Turbine.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/Turbine.java,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- Turbine.java	2 Feb 2004 11:19:42 -0000	1.47
  +++ Turbine.java	18 Feb 2004 14:38:56 -0000	1.48
  @@ -56,10 +56,12 @@
   
   import java.io.File;
   import java.io.FileInputStream;
  +import java.io.FileNotFoundException;
   import java.io.IOException;
   import java.util.Date;
   import java.util.Iterator;
   import java.util.Properties;
  +
   import javax.servlet.ServletConfig;
   import javax.servlet.ServletContext;
   import javax.servlet.ServletException;
  @@ -67,25 +69,21 @@
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
   
  +import org.apache.commons.configuration.Configuration;
  +import org.apache.commons.configuration.ConfigurationFactory;
  +import org.apache.commons.configuration.PropertiesConfiguration;
   import org.apache.commons.http.HttpUtils;
   import org.apache.commons.lang.StringUtils;
   import org.apache.commons.lang.exception.ExceptionUtils;
  -import org.apache.commons.logging.LogFactory;
   import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   import org.apache.commons.xo.Mapper;
  -
   import org.apache.fulcrum.ServiceManager;
   import org.apache.fulcrum.TurbineServices;
  -
  -import org.apache.commons.configuration.Configuration;
  -import org.apache.commons.configuration.ConfigurationConverter;
  -import org.apache.commons.configuration.ConfigurationFactory;
  -import org.apache.commons.configuration.PropertiesConfiguration;
  -
  +import org.apache.log4j.PropertyConfigurator;
   import org.apache.turbine.modules.ModuleLoader;
   import org.apache.turbine.pipeline.TurbinePipeline;
   import org.apache.turbine.services.rundata.RunDataService;
  -import org.apache.log4j.PropertyConfigurator;
   
   /**
    * Turbine is the main servlet for the entire system. It is <code>final</code>
  @@ -131,8 +129,8 @@
       extends HttpServlet
       implements TurbineConstants
   {
  -    private static final Log log
  -        = LogFactory.getLog( Turbine.class );
  +    /** Logging class from commons.logging */
  +    private static Log log = LogFactory.getLog(Turbine.class);
   
       /**
        * In certain situations the init() method is called more than once,
  @@ -661,31 +659,37 @@
           configuration.setProperty(WEBAPP_ROOT,
               config.getServletContext().getRealPath(""));
   
  -        // This is for our log4j setup. We are embedding
  -        // the log4j configuration in the TRP but log4j
  -        // must be initialized with a Properties object.
  -        // We load it here so that we can add a "webapp"
  -        // property that will be used in the form of
  -        // ${webapp} in log4j properties. We need this
  -        // so that the log files can be placed in
  -        // the webapp space.
  -     /*   String trProps =
  -        	findInitParameter(context, config,
  -        			TurbineConfig.PROPERTIES_KEY,
  -        	"TurbineResources.properties");
  -        String trPropsFile = getRealPath(trProps);*/
  -        Properties p = ConfigurationConverter.getProperties(configuration);
  -      /*  p.load(new FileInputStream(trPropsFile));
  -        p.setProperty(APPLICATION_ROOT, getApplicationRoot());*/
  -
  -        // FIXME: Configures log4j directly with the supplied properties. The
  -        //        plan is to eliminate this, and instead allow logging to be
  -        //        initialized by a component, which could init any logging
  -        //        mechanism supported by commons-logging. However it is
  -        //        important that logging be intialized early, so we will need
  -        //        to address that in the component loader.
  +//
  +        // Set up logging as soon as possible
  +        //
  +        String log4jFile = configuration.getString(LOG4J_CONFIG_FILE,
  +                LOG4J_CONFIG_FILE_DEFAULT);
   
  -        PropertyConfigurator.configure(p);        
  +        log4jFile = getRealPath(log4jFile);
  +
  +        //
  +        // Load the config file above into a Properties object and
  +        // fix up the Application root
  +        //
  +        Properties p = new Properties();
  +        try
  +        {
  +            p.load(new FileInputStream(log4jFile));
  +            p.setProperty(APPLICATION_ROOT, getApplicationRoot());
  +            PropertyConfigurator.configure(p);
  +
  +            //
  +            // Rebuild our log object with a configured commons-logging
  +            log = LogFactory.getLog(Turbine.class.getName());
  +
  +            log.info("Configured log4j from " + log4jFile);
  +        }
  +        catch (FileNotFoundException fnf)
  +        {
  +            System.err.println("Could not open Log4J configuration file "
  +                    + log4jFile + ": ");
  +            fnf.printStackTrace();
  +        }     
           
           serviceManager.setConfiguration(configuration);
   
  
  
  
  1.16      +6 -0      jakarta-turbine-3/src/java/org/apache/turbine/TurbineConstants.java
  
  Index: TurbineConstants.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/TurbineConstants.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- TurbineConstants.java	16 Apr 2002 21:30:15 -0000	1.15
  +++ TurbineConstants.java	18 Feb 2004 14:38:56 -0000	1.16
  @@ -340,4 +340,10 @@
        * standalone is assumed.
        */
       public static final String INTEGRATED = "integrated";
  +    
  +    /** The key for the Log4J File */
  +    public static final String LOG4J_CONFIG_FILE = "log4j.file";
  +
  +    /** The default value for the Log4J File */
  +    public static final String LOG4J_CONFIG_FILE_DEFAULT = "/WEB-INF/conf/log4j.properties";    
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org