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/09/01 00:40:15 UTC
cvs commit: jakarta-turbine-fulcrum/src/core/java/org/apache/fulcrum BaseServiceBroker.java
jvanzyl 01/08/31 15:40:15
Modified: src/core/java/org/apache/fulcrum BaseServiceBroker.java
Log:
- add a routine to detect whether log4j has been configured or
not. still have to add routines to configure the logging when
fulcrum is running in stand-alone mode.
possibly allow for the specification of a properties file,
or allow the logging to be configured programmtically or look
for a properties file on the classpath. maybe a combination
of all the above.
Revision Changes Path
1.7 +46 -4 jakarta-turbine-fulcrum/src/core/java/org/apache/fulcrum/BaseServiceBroker.java
Index: BaseServiceBroker.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/src/core/java/org/apache/fulcrum/BaseServiceBroker.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- BaseServiceBroker.java 2001/08/31 08:00:28 1.6
+++ BaseServiceBroker.java 2001/08/31 22:40:14 1.7
@@ -92,7 +92,7 @@
* @author <a href="mailto:krzewski@e-point.pl">Rafal Krzewski</a>
* @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
* @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
- * @version $Id: BaseServiceBroker.java,v 1.6 2001/08/31 08:00:28 jvanzyl Exp $
+ * @version $Id: BaseServiceBroker.java,v 1.7 2001/08/31 22:40:14 jvanzyl Exp $
*/
public abstract class BaseServiceBroker implements ServiceBroker
{
@@ -129,7 +129,7 @@
* True if logging should go throught
* LoggingService, false if not.
*/
- protected boolean loggingEnabled = false;
+ protected boolean loggingConfigured;
/**
* These are objects that the parent application
@@ -165,6 +165,44 @@
protected BaseServiceBroker()
{
}
+
+ /**
+ * Determine whether log4j has already been configured.
+ *
+ * @return boolean is log4j configured
+ */
+ protected boolean isLoggingConfigured()
+ {
+ // This is a note from Ceki, taken from a message on the log4j
+ // user list:
+ //
+ // Having defined categories does not necessarily mean configuration.
+ // Remember that most categories are created outside the configuration file.
+ // What you want to check for is the existence of appenders. The correct
+ // procedure is to first check for appenders in the root category and if that
+ // returns no appenders to check in other categories.
+
+ Enumeration enum = Category.getRoot().getAllAppenders();
+
+ if(!(enum instanceof org.apache.log4j.helpers.NullEnumeration))
+ {
+ return true;
+ }
+ else
+ {
+ Enumeration cats = Category.getCurrentCategories();
+ while(cats.hasMoreElements())
+ {
+ Category c = (Category) cats.nextElement();
+ if(!(c.getAllAppenders() instanceof org.apache.log4j.helpers.NullEnumeration))
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
/**
* Set the configuration object for the services broker.
@@ -218,6 +256,10 @@
// to throw in the event these requirements
// aren't satisfied.
+ // Check to see if a parent application has already
+ // configured the logging.
+ loggingConfigured = isLoggingConfigured();
+
// Create the mapping between service names
// and their classes.
initMapping();
@@ -728,7 +770,7 @@
*/
public void notice(String msg)
{
- if (loggingEnabled)
+ if (loggingConfigured)
{
category.info(msg);
}
@@ -750,7 +792,7 @@
*/
public void error(Throwable t)
{
- if (loggingEnabled)
+ if (loggingConfigured)
{
category.info(t);
category.info(stackTrace(t));
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org