Index: src/java/org/apache/turbine/Turbine.java
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-2/src/java/org/apache/turbine/Turbine.java,v
retrieving revision 1.5
diff -u -r1.5 Turbine.java
--- src/java/org/apache/turbine/Turbine.java	2001/09/26 01:23:02	1.5
+++ src/java/org/apache/turbine/Turbine.java	2001/10/09 18:27:13
@@ -157,7 +157,13 @@
      * will operate.
      */
     private static String applicationRoot;
-    
+
+    /**
+     * instance of turbine services
+     */
+    private TurbineServices services =
+            (TurbineServices) TurbineServices.getInstance();
+
     /**
      * Server information. This information needs to
      * be made available to processes that do not have
@@ -204,10 +210,6 @@
                 {
                     applicationRoot = config.getServletContext().getRealPath("");
                 }                    
-                
-                // Initalize TurbineServices and init bootstrap services
-                TurbineServices services =
-                    (TurbineServices) TurbineServices.getInstance();
 
                 // Initialize essential services (Resources & Logging)
                 services.initPrimaryServices(config);
@@ -222,15 +224,15 @@
                 
                 // Initialize other services that require early init
                 services.initServices(config, false);
+
+                log ("Turbine: init() Ready to Rumble!");
             }
             catch ( Exception e )
             {
                 // save the exception to complain loudly later :-)
                 initFailure = e;
                 log ("Turbine: init() failed: " + StringUtils.stackTrace(e));
-                return;
             }
-            log ("Turbine: init() Ready to Rumble!");
         }
     }
 
@@ -758,5 +760,27 @@
         }
         
         return applicationRoot + "/" + path;
-    }        
+    }
+
+    /**
+     * logs message using turbine's logging facility
+     * @param msg   message to be logged
+     */
+    public void log(String msg)
+    {
+        services.notice(msg);
+    }
+
+    /**
+     * Writes an explanatory message and a stack trace
+     * for a given <code>Throwable</code> exception
+     * @param message 		the message
+     * @param t			the error
+     */
+
+    public void log(String message, Throwable t)
+    {
+        services.notice(message);
+        services.error(t);
+    }
 }
Index: src/java/org/apache/turbine/services/TurbineServices.java
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-2/src/java/org/apache/turbine/services/TurbineServices.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 TurbineServices.java
--- src/java/org/apache/turbine/services/TurbineServices.java	2001/08/16 05:08:48	1.1.1.1
+++ src/java/org/apache/turbine/services/TurbineServices.java	2001/10/09 18:27:14
@@ -57,6 +57,9 @@
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Properties;
+import java.util.Vector;
+import java.io.StringWriter;
+import java.io.PrintWriter;
 import javax.servlet.ServletConfig;
 import org.apache.turbine.services.logging.LoggingService;
 import org.apache.turbine.services.resources.ResourceService;
@@ -133,6 +136,12 @@
     /** True if logging should go throught LoggingService, false if not. */
     private boolean enabledLogging = false;
 
+    /** caches log messages before logging is enabled */
+    private Vector logCache = new Vector(5);
+
+    /** the logger */
+    private LoggingService logger;
+
     /**
      * This constructor is protected to force clients to use
      * getInstance() to access this class.
@@ -160,25 +169,48 @@
     {
         // Resurce service must start as the very first
         String resourcesClass = config.getInitParameter(RESOURCES_CLASS_KEY);
-        if (resourcesClass == null)
-        {
-            resourcesClass = RESOURCES_CLASS_DEFAULT;
-        }
-        mapping.put(ResourceService.SERVICE_NAME, resourcesClass);
-        initService (ResourceService.SERVICE_NAME, config);
 
-        // Now logging can be initailzed
-        String loggingClass = config.getInitParameter(LOGGING_CLASS_KEY);
-        if (loggingClass == null)
+        try
         {
-            loggingClass = LOGGING_CLASS_DEFAULT;
-        }
-        mapping.put(LoggingService.SERVICE_NAME, loggingClass);
-        initService (LoggingService.SERVICE_NAME, config);
+            if (resourcesClass == null)
+            {
+                resourcesClass = RESOURCES_CLASS_DEFAULT;
+            }
+            mapping.put(ResourceService.SERVICE_NAME, resourcesClass);
+            initService (ResourceService.SERVICE_NAME, config);
+
 
-        // All further messages will go through LoggingService
-        enableLogging();
+            // Now logging can be initailzed
+            String loggingClass = config.getInitParameter(LOGGING_CLASS_KEY);
+            if (loggingClass == null)
+            {
+                loggingClass = LOGGING_CLASS_DEFAULT;
+            }
+            mapping.put(LoggingService.SERVICE_NAME, loggingClass);
+            try
+            {
+                initService (LoggingService.SERVICE_NAME, config);
+                logger = getLogger();
+            }
+            catch (InitializationException e)
+            {
+                mapping.remove(LoggingService.SERVICE_NAME);
+                throw e;
+            }
+            catch (InstantiationException e)
+            {
+                mapping.remove(LoggingService.SERVICE_NAME);
+                throw e;
+            }
 
+        }
+        finally
+        {
+            // All further messages will go through LoggingService
+            // if logging service could not be initialized we still want
+            // to enable logging for further messages to go to console
+            enableLogging();
+        }
         // Since we have ResourceService running, real mappings of services
         // may be loaded now
         initMapping();
@@ -343,7 +375,6 @@
     {
         if (enabledLogging)
         {
-            LoggingService logger = getLogger();
             if (logger == null)
             {
                 System.out.println("(!) NOTICE: " + msg);
@@ -355,7 +386,8 @@
         }
         else
         {
-            System.out.println("NOTICE: " + msg);
+            // cache the message to log as soon as logiing is on
+            logCache.add(msg);
         }
     }
 
@@ -373,7 +405,6 @@
     {
         if (enabledLogging)
         {
-            LoggingService logger = getLogger();
             if (logger == null)
             {
                 System.out.println("(!) ERROR: " + t.getMessage());
@@ -385,8 +416,11 @@
         }
         else
         {
-            System.out.println("ERROR: " + t.getMessage());
-            t.printStackTrace();
+            // cache the message to log as soon as logiing is on
+            logCache.add("ERROR: " + t.getMessage());
+            StringWriter sw = new StringWriter();
+            t.printStackTrace(new PrintWriter(sw));
+            logCache.add(sw.toString());
         }
 
     }
@@ -397,12 +431,18 @@
      */
     private void enableLogging()
     {
-        LoggingService logger = getLogger();
-        if (logger != null)
+        enabledLogging = true;
+        //log all cached log messages
+        for (int i = 0; i < logCache.size(); i++)
         {
-            logger.info("ServiceBroker: LoggingService enabled.");
-            enabledLogging = true;
+            String s = (String) logCache.elementAt(i);
+            notice(s);
         }
+        //dispose of the cache
+        logCache = null;
+
+        notice("ServiceBroker: LoggingService enabled.");
+
     }
 
     /**

