You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jv...@apache.org on 2001/10/12 18:41:22 UTC
cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/services TurbineServices.java
jvanzyl 01/10/12 09:41:22
Modified: src/java/org/apache/turbine Turbine.java
src/java/org/apache/turbine/services TurbineServices.java
Log:
- applying fedor's logging patches
Revision Changes Path
1.7 +33 -8 jakarta-turbine-2/src/java/org/apache/turbine/Turbine.java
Index: Turbine.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/Turbine.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Turbine.java 2001/10/10 13:35:33 1.6
+++ Turbine.java 2001/10/12 16:41:22 1.7
@@ -109,7 +109,7 @@
* @author <a href="mailto:krzewski@e-point.pl">Rafal Krzewski</a>
* @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
* @author <a href="mailto:sean@informage.net">Sean Legassick</a>
- * @version $Id: Turbine.java,v 1.6 2001/10/10 13:35:33 jvanzyl Exp $
+ * @version $Id: Turbine.java,v 1.7 2001/10/12 16:41:22 jvanzyl Exp $
*/
public class Turbine
extends HttpServlet
@@ -149,7 +149,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
@@ -201,9 +207,6 @@
// a running Turbine application.
createRuntimeDirectories();
- // Initalize TurbineServices and init bootstrap services
- TurbineServices services =
- (TurbineServices) TurbineServices.getInstance();
// Initialize essential services (Resources & Logging)
services.initPrimaryServices(config);
@@ -218,15 +221,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!");
}
}
@@ -780,5 +783,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);
+ }
}
1.2 +65 -25 jakarta-turbine-2/src/java/org/apache/turbine/services/TurbineServices.java
Index: TurbineServices.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/TurbineServices.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TurbineServices.java 2001/08/16 05:08:48 1.1
+++ TurbineServices.java 2001/10/12 16:41:22 1.2
@@ -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;
@@ -71,7 +74,7 @@
* @author <a href="mailto:burton@apache.org">Kevin Burton</a>
* @author <a href="mailto:krzewski@e-point.pl">Rafal Krzewski</a>
* @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
- * @version $Id: TurbineServices.java,v 1.1 2001/08/16 05:08:48 jvanzyl Exp $
+ * @version $Id: TurbineServices.java,v 1.2 2001/10/12 16:41:22 jvanzyl Exp $
*/
public class TurbineServices
extends BaseServiceBroker
@@ -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.");
+
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org