leif 2002/08/06 21:55:55
Modified: fortress build.xml default.properties
fortress/examples/src/java/org/apache/excalibur/fortress/examples/swing
Main.java SwingContainer.instruments
SwingContainer.roles SwingContainer.xlog
fortress/src/java/org/apache/excalibur/fortress
AbstractContainer.java DefaultContainerManager.java
fortress/src/java/org/apache/excalibur/fortress/util
AbstractRoleManager.java ContextManager.java
ExcaliburRoleManager.java
fortress/src/test/org/apache/excalibur/fortress/util/test
ConfigurableRoleManagerTestCase.java
ExcaliburRoleManagerTestCase.java
Log:
Reworked the logging to make use of more descriptive category names.
Added the ability to configure log levels and category names in a more
flexible
way.
Revision Changes Path
1.36 +1 -0 jakarta-avalon-excalibur/fortress/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/build.xml,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- build.xml 31 Jul 2002 06:49:48 -0000 1.35
+++ build.xml 7 Aug 2002 04:55:55 -0000 1.36
@@ -49,6 +49,7 @@
<pathelement location="${excalibur-concurrent.jar}"/>
<pathelement location="${excalibur-thread.jar}"/>
<pathelement location="${xalan.jar}"/>
+ <pathelement location="${jaxen-full.jar}"/>
<path refid="project.class.path"/>
</path>
<property name="cp" refid="test.class.path"/>
1.27 +1 -0 jakarta-avalon-excalibur/fortress/default.properties
Index: default.properties
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/default.properties,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- default.properties 4 Aug 2002 01:07:39 -0000 1.26
+++ default.properties 7 Aug 2002 04:55:55 -0000 1.27
@@ -59,6 +59,7 @@
excalibur-xmlutil.home=${basedir}/../xmlutil/dist
excalibur-xmlutil.lib=${excalibur-xmlutil.home}
excalibur-xmlutil.jar=${excalibur-xmlutil.lib}/excalibur-xmlutil-1.0.jar
+jaxen-full.jar=${basedir}/../xmlutil/lib/jaxen-full.jar
# ----- Excalibur XMLBundle, version 1.0 or later -----
excalibur-xmlbundle.home=${basedir}/../xmlbundle/dist
1.4 +1 -2
jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/swing/Main.java
Index: Main.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/swing/Main.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Main.java 6 Aug 2002 20:47:25 -0000 1.3
+++ Main.java 7 Aug 2002 04:55:55 -0000 1.4
@@ -18,7 +18,6 @@
import org.apache.excalibur.fortress.ContainerManager;
import org.apache.excalibur.fortress.DefaultContainerManager;
import org.apache.excalibur.fortress.util.ContextBuilder;
-import org.apache.excalibur.fortress.util.ContextManager;
/**
* Fortress container example.
1.2 +1 -1
jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/swing/SwingContainer.instruments
Index: SwingContainer.instruments
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/swing/SwingContainer.instruments,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SwingContainer.instruments 5 Aug 2002 04:40:39 -0000 1.1
+++ SwingContainer.instruments 7 Aug 2002 04:55:55 -0000 1.2
@@ -1,4 +1,4 @@
-<instrument logger="im">
+<instrument logger="system.instrument">
<name>SwingContainer</name>
<description>Fortress SwingContainer Example</description>
1.2 +1 -1
jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/swing/SwingContainer.roles
Index: SwingContainer.roles
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/swing/SwingContainer.roles,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SwingContainer.roles 4 Jul 2002 09:43:24 -0000 1.1
+++ SwingContainer.roles 7 Aug 2002 04:55:55 -0000 1.2
@@ -1,4 +1,4 @@
-<fortress-roles>
+<fortress-roles logger="system.roles">
<role name="org.apache.excalibur.fortress.examples.components.Translator">
<component shorthand="translator"
1.3 +19 -12
jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/swing/SwingContainer.xlog
Index: SwingContainer.xlog
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/swing/SwingContainer.xlog,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SwingContainer.xlog 5 Aug 2002 04:40:39 -0000 1.2
+++ SwingContainer.xlog 7 Aug 2002 04:55:55 -0000 1.3
@@ -1,21 +1,28 @@
-<logkit>
+<logkit logger="system.logkit" log-level="INFO">
+
<factories>
- <factory type="file"
class="org.apache.avalon.excalibur.logger.factory.FileTargetFactory"/>
+ <factory type="stream"
class="org.apache.avalon.excalibur.logger.factory.StreamTargetFactory"/>
</factories>
<targets>
- <file id="root">
- <filename>fortress-examples.log</filename>
+ <stream id="console">
+ <stream>System.out</stream>
<format type="extended">
- %7.7{priority} %5.5{time} [%16.16{category}] (%{context}):
%{message}\n%{throwable}
+ %7.7{priority} %23.23{time:yyyy-MM-dd HH:mm:ss.SSS}
[%24.24{category}] (%{context}): %{message}\n%{throwable}
</format>
- </file>
- </targets>
+ </stream>
+ </targets>
+
+ <categories>
+ <!-- Log output from the default logger -->
+ <category name="" log-level="DEBUG">
+ <log-target id-ref="console"/>
+ </category>
- <categories>
- <category name="" log-level="DEBUG">
- <log-target id-ref="root"/>
- </category>
- </categories>
+ <!-- Log output from the fortress system -->
+ <category name="system" log-level="INFO">
+ <log-target id-ref="console"/>
+ </category>
+ </categories>
</logkit>
1.54 +22 -15
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/AbstractContainer.java
Index: AbstractContainer.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/AbstractContainer.java,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- AbstractContainer.java 6 Aug 2002 19:41:17 -0000 1.53
+++ AbstractContainer.java 7 Aug 2002 04:55:55 -0000 1.54
@@ -54,8 +54,6 @@
import java.util.Iterator;
import java.util.List;
-import org.apache.excalibur.instrument.Instrumentable;
-import org.apache.excalibur.instrument.InstrumentManager;
import org.apache.avalon.excalibur.collections.BucketMap;
import org.apache.avalon.excalibur.collections.FixedSizeBuffer;
import org.apache.avalon.excalibur.logger.LoggerManager;
@@ -64,14 +62,17 @@
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
+
import org.apache.excalibur.event.Queue;
import org.apache.excalibur.event.command.Command;
import org.apache.excalibur.fortress.handler.ComponentHandler;
@@ -81,6 +82,8 @@
import org.apache.excalibur.fortress.lookup.FortressServiceSelector;
import org.apache.excalibur.fortress.util.ExcaliburRoleManager;
import org.apache.excalibur.fortress.util.RoleManager;
+import org.apache.excalibur.instrument.Instrumentable;
+import org.apache.excalibur.instrument.InstrumentManager;
import org.apache.excalibur.mpool.PoolManager;
/**
@@ -112,14 +115,6 @@
protected LifecycleExtensionManager m_extManager;
/**
- * Wrap this so that ComponentStateValidator functions properly.
- */
- public void enableLogging( Logger logger )
- {
- super.enableLogging( logger );
- }
-
- /**
* Pull the manager items from the context so we can use them to set up
* the system.
*/
@@ -141,7 +136,8 @@
if ( getLogger().isDebugEnabled() )
{
- getLogger().debug( "No Container.EXTENSION_MANAGER is given,
installing default lifecycle extension manager with 0 extensions" );
+ getLogger().debug( "No Container.EXTENSION_MANAGER is given,
installing default "
+ + "lifecycle extension manager with 0 extensions" );
}
}
@@ -163,7 +159,8 @@
catch( ContextException ce )
{
m_commandQueue = null;
- getLogger().warn( "No Container.COMMAND_QUEUE is given, all
management will be performed synchronously" );
+ getLogger().warn( "No Container.COMMAND_QUEUE is given, all
management will be "
+ + "performed synchronously" );
}
try
@@ -172,7 +169,16 @@
}
catch( ContextException ce )
{
- m_roleManager = new ExcaliburRoleManager();
+ try
+ {
+ m_roleManager = new ExcaliburRoleManager();
+ ContainerUtil.enableLogging( m_roleManager,
getLogger().getChildLogger( "roles" ) );
+ ContainerUtil.initialize( m_roleManager );
+ }
+ catch ( Exception e )
+ {
+ throw new ContextException( "Unable to create default role
manager", e );
+ }
}
m_instrumentManager = (InstrumentManager)m_context.get(
Container.INSTRUMENT_MANAGER );
@@ -220,7 +226,8 @@
{
if( !hintMap.containsKey( "selector" ) )
{
- hintMap.put( "selector", new FortressServiceSelector(
this, role, m_extManager, m_context ) );
+ hintMap.put( "selector",
+ new FortressServiceSelector( this, role,
m_extManager, m_context ) );
}
}
else
1.20 +4 -4
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/DefaultContainerManager.java
Index: DefaultContainerManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/DefaultContainerManager.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- DefaultContainerManager.java 7 Aug 2002 03:22:11 -0000 1.19
+++ DefaultContainerManager.java 7 Aug 2002 04:55:55 -0000 1.20
@@ -105,8 +105,8 @@
public DefaultContainerManager( ContextManager contextManager, Logger
logger )
{
this.contextManager = contextManager;
- this.logger = logger == null ?
- createLoggerFromContext(
this.contextManager.getContainerManagerContext() ) : logger;
+ this.logger = ( logger == null ?
+ createLoggerFromContext(
this.contextManager.getContainerManagerContext() ) : logger );
}
public DefaultContainerManager( Context initParameters )
@@ -158,7 +158,7 @@
catch( ContextException ce )
{
Logger consoleLogger = new ConsoleLogger();
- consoleLogger.error( "Could not obtain logger manager from init
parameters "
+ consoleLogger.error( "ContainerManager could not obtain logger
manager from context "
+ "(this should not happen). Using console instead." );
return consoleLogger;
}
1.11 +117 -16
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util/AbstractRoleManager.java
Index: AbstractRoleManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util/AbstractRoleManager.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- AbstractRoleManager.java 6 Aug 2002 19:41:19 -0000 1.10
+++ AbstractRoleManager.java 7 Aug 2002 04:55:55 -0000 1.11
@@ -49,6 +49,8 @@
*/
package org.apache.excalibur.fortress.util;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -62,6 +64,7 @@
* @since 4.1
*/
public abstract class AbstractRoleManager
+ extends AbstractLogEnabled
implements RoleManager
{
protected static final String EMPTY_STRING = "";
@@ -124,6 +127,12 @@
{
final Class klass;
Class handlerKlass;
+
+ if ( getLogger().isDebugEnabled() )
+ {
+ getLogger().debug( "setup role: name='" + shortName + "',
role='" + role + "', "
+ + "class='" + className + "', handler='" + handlerClassName
+ "'" );
+ }
try
{
@@ -134,6 +143,11 @@
// Do not store reference if class does not exist.
return;
}
+ catch( NoClassDefFoundError e )
+ {
+ // Do not store reference if class does not exist.
+ return;
+ }
try
{
@@ -173,11 +187,25 @@
{
if( shorthandName == null ) return null;
- final Class component = (Class)m_shorthands.get( shorthandName );
+ Class component = (Class)m_shorthands.get( shorthandName );
if( null == component && null != m_parent )
{
- return m_parent.getClassForName( shorthandName );
+ component = m_parent.getClassForName( shorthandName );
+ }
+
+ if ( getLogger().isDebugEnabled() )
+ {
+ if ( component == null )
+ {
+ getLogger().debug( "looking up class with shorthand '" +
shorthandName
+ + "' but a class was not found." );
+ }
+ else
+ {
+ getLogger().debug( "looking up class with shorthand '" +
shorthandName
+ + "' returning '" + component.getName() + "'" );
+ }
}
return component;
@@ -189,16 +217,30 @@
* this RoleManager does not have the match, and there is a parent
* RoleManager, the parent will be asked to resolve the role.
*
- * @param shorthandName The shortname that is an alias for the role.
+ * @param klass The class whose role is being requested.
* @return the official role name.
*/
public final String getNameForClass( final Class klass )
{
- final String shorthandName = (String)m_shorthands.get( klass );
+ String shorthandName = (String)m_shorthands.get( klass );
if( null == shorthandName && null != m_parent )
{
- return m_parent.getNameForClass( klass );
+ shorthandName = m_parent.getNameForClass( klass );
+ }
+
+ if ( getLogger().isDebugEnabled() )
+ {
+ if ( shorthandName == null )
+ {
+ getLogger().debug( "looking up shorthand with class '" +
klass.getName()
+ + "' but a shorthand was not found." );
+ }
+ else
+ {
+ getLogger().debug( "looking up shorthand with class '" +
klass.getName()
+ + "' returning '" + shorthandName + "'" );
+ }
}
return shorthandName;
@@ -210,18 +252,32 @@
* not have the match, and there is a parent RoleManager, the parent will
* be asked to resolve the handler's class name.
*
- * @param role The role that has a default implementation.
+ * @param klass The role that has a default implementation.
* @return the Fully Qualified Class Name (FQCN) for the role.
*/
- public final Class getHandlerClassForClass( final Class className )
+ public final Class getHandlerClassForClass( final Class klass )
{
- final Class handler = (Class)m_handlerNames.get( className );
+ Class handler = (Class)m_handlerNames.get( klass );
if( null == handler && null != m_parent )
{
- return m_parent.getHandlerClassForClass( className );
+ handler = m_parent.getHandlerClassForClass( klass );
}
+ if ( getLogger().isDebugEnabled() )
+ {
+ if ( handler == null )
+ {
+ getLogger().debug( "looking up handler class with class '" +
klass.getName()
+ + "' but a handler was not found." );
+ }
+ else
+ {
+ getLogger().debug( "looking up handler class with class '" +
klass.getName()
+ + "' returning '" + handler.getName() + "'" );
+ }
+ }
+
return handler;
}
@@ -237,14 +293,53 @@
*/
public final Class[] getClassesForRole( final String role )
{
- final List classes = (List)m_classNames.get( role );
+ List classes = (List)m_classNames.get( role );
+ Class[] classAry;
if( null == classes && null != m_parent )
{
- return m_parent.getClassesForRole( role );
+ classAry = m_parent.getClassesForRole( role );
+ }
+ else
+ {
+ // Convert the list into an array
+ if ( classes == null )
+ {
+ classAry = new Class[0];
+ }
+ else
+ {
+ classAry = new Class[classes.size()];
+ classes.toArray( classAry );
+ }
}
- return (Class[])classes.toArray( new Class[]{} );
+ if ( getLogger().isDebugEnabled() )
+ {
+ if ( classes == null )
+ {
+ getLogger().debug( "looking up classes with role '" + role
+ + "' but no classes were found." );
+ }
+ else
+ {
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < classAry.length; i++ )
+ {
+ if ( i > 0 )
+ {
+ sb.append( ", " );
+ }
+ sb.append( "'" );
+ sb.append( classAry[i].getName() );
+ sb.append( "'" );
+ }
+ getLogger().debug( "looking up classes with role '" + role
+ + "' returning [" + sb + "]" );
+ }
+ }
+
+ return classAry;
}
/**
@@ -260,18 +355,24 @@
*/
public final String getRoleForClass( final Class klass )
{
- final String role = (String)m_classNames.get( klass );
+ String role = (String)m_classNames.get( klass );
if( null == role )
{
if( null != m_parent )
{
- return m_parent.getRoleForClass( klass );
+ role = m_parent.getRoleForClass( klass );
}
else
{
- return EMPTY_STRING;
+ role = EMPTY_STRING;
}
+ }
+
+ if ( getLogger().isDebugEnabled() )
+ {
+ getLogger().debug( "looking up role with class '" +
klass.getName()
+ + "' returning '" + role + "'" );
}
return role;
1.33 +95 -42
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util/ContextManager.java
Index: ContextManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util/ContextManager.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- ContextManager.java 7 Aug 2002 03:28:48 -0000 1.32
+++ ContextManager.java 7 Aug 2002 04:55:55 -0000 1.33
@@ -51,9 +51,10 @@
import java.util.ArrayList;
import java.util.Iterator;
-import org.apache.excalibur.instrument.manager.DefaultInstrumentManager;
-import org.apache.avalon.excalibur.logger.LogKitLoggerManager;
+
import org.apache.avalon.excalibur.logger.LoggerManager;
+import org.apache.avalon.excalibur.logger.LogKitLoggerManager;
+
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.activity.Startable;
@@ -70,13 +71,16 @@
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.logger.LogKitLogger;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.service.DefaultServiceManager;
import org.apache.avalon.framework.service.ServiceManager;
+
import org.apache.excalibur.event.Queue;
import org.apache.excalibur.event.command.CommandManager;
import org.apache.excalibur.event.command.ThreadManager;
import org.apache.excalibur.event.command.TPCThreadManager;
+import org.apache.excalibur.instrument.manager.DefaultInstrumentManager;
import org.apache.excalibur.mpool.DefaultPoolManager;
import org.apache.excalibur.mpool.PoolManager;
import org.apache.excalibur.source.Source;
@@ -84,6 +88,9 @@
import org.apache.excalibur.source.impl.ResourceSourceFactory;
import org.apache.excalibur.source.impl.SourceResolverImpl;
+import org.apache.log.Hierarchy;
+import org.apache.log.Priority;
+
/**
* <p>The ContextManager is used to manage the values in a Container's
* Context. The ContainerManager uses this helper class to create the
@@ -111,6 +118,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Leo Sutic</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a>
* @version CVS $Revision$ $Date$
* @since 4.1
*/
@@ -156,7 +164,7 @@
private Logger logger;
private final Logger primordialLogger;
private ComponentManager manager;
-
+
/**
* The components that are "owned" by this context and should
* be disposed by it. Any manager that is created as a result
@@ -450,7 +458,13 @@
assumeOwnership( cm );
assumeOwnership( tm );
- ContainerUtil.enableLogging( tm, logger );
+ // Get the context Logger Manager
+ LoggerManager loggerManager = (LoggerManager)childContext.get(
LOGGER_MANAGER );
+
+ // Get the logger for the thread manager
+ Logger tmLogger = loggerManager.getLoggerForCategory(
"system.threadmgr" );
+
+ ContainerUtil.enableLogging( tm, tmLogger );
ContainerUtil.parameterize( tm, buildCommandQueueConfig() );
ContainerUtil.initialize( tm );
@@ -533,9 +547,10 @@
{
}
- Configuration config = getConfiguration( ROLE_MANAGER_CONFIGURATION,
ROLE_MANAGER_CONFIGURATION_URI );
+ Configuration roleConfig =
+ getConfiguration( ROLE_MANAGER_CONFIGURATION,
ROLE_MANAGER_CONFIGURATION_URI );
- if( config == null )
+ if( roleConfig == null )
{
// See if we can inherit from the parent...
try
@@ -547,20 +562,27 @@
}
catch( ContextException ce )
{
- // No RoleManager available anywhere. (Set one up.)
-
- RoleManager rm = new ExcaliburRoleManager();
-
- assumeOwnership( rm );
- childContext.put( ROLE_MANAGER, rm );
-
- return;
+ // No RoleManager available anywhere.
+ roleConfig = EMPTY_CONFIG;
}
}
- ConfigurableRoleManager rm = new ConfigurableRoleManager( new
ExcaliburRoleManager() );
+ // Get the context Logger Manager
+ LoggerManager loggerManager = (LoggerManager)childContext.get(
LOGGER_MANAGER );
- rm.configure( config );
+ // Create a logger for the role manager
+ Logger rmLogger = loggerManager.getLoggerForCategory(
+ roleConfig.getAttribute( "logger", "system.roles" ) );
+
+ // Create a parent role manager with all the default roles
+ ExcaliburRoleManager erm = new ExcaliburRoleManager();
+ erm.enableLogging( rmLogger.getChildLogger( "defaults" ) );
+ erm.initialize();
+
+ // Create a role manager with the configured roles
+ ConfigurableRoleManager rm = new ConfigurableRoleManager( erm );
+ rm.enableLogging( rmLogger );
+ rm.configure( roleConfig );
assumeOwnership( rm );
childContext.put( ROLE_MANAGER, rm );
@@ -711,10 +733,12 @@
{
// Should we set one up?
// Try to get a configuration for it...
- Configuration loggerManagerConfig = getConfiguration(
LOGGER_MANAGER_CONFIGURATION, LOGGER_MANAGER_CONFIGURATION_URI );
+ Configuration loggerManagerConfig =
+ getConfiguration( LOGGER_MANAGER_CONFIGURATION,
LOGGER_MANAGER_CONFIGURATION_URI );
if( loggerManagerConfig == null )
{
- // No config.
+ // No config specified.
+
// Does the parent supply a logger manager?
try
{
@@ -725,13 +749,47 @@
}
catch( ContextException cex )
{
+ // The parent did not supply a Logger Manager, so create
an empty
+ // configuration so that a default logger can be
created.
+ loggerManagerConfig = EMPTY_CONFIG;
}
}
-
- String logCategory = (String)get( rootContext, LOG_CATEGORY,
get( childContext, LOG_CATEGORY, null ) );
-
- LogKitLoggerManager logManager = new LogKitLoggerManager(
logCategory );
-
+
+ // Resolve the prefix to use for this Logger Manager
+ String logPrefix = (String)get( rootContext, LOG_CATEGORY,
+ get( childContext, LOG_CATEGORY, null ) );
+
+ // Resolve a name for the logger, taking the logPrefix into
account
+ String lmDefaultLoggerName;
+ String lmLoggerName;
+ if ( logPrefix == null )
+ {
+ lmDefaultLoggerName = "";
+ lmLoggerName = loggerManagerConfig.getAttribute( "logger",
"system.logkit" );
+ }
+ else
+ {
+ lmDefaultLoggerName = logPrefix;
+ lmLoggerName = logPrefix +
org.apache.log.Logger.CATEGORY_SEPARATOR
+ + loggerManagerConfig.getAttribute( "logger",
"system.logkit" );
+ }
+
+ // Create the default logger for the Logger Manager.
+ org.apache.log.Logger lmDefaultLogger =
+ Hierarchy.getDefaultHierarchy().getLoggerFor(
lmDefaultLoggerName );
+ // The default logger is not used until after the logger conf
has been loaded
+ // so it is possible to configure the priority there.
+ lmDefaultLogger.setPriority( Priority.DEBUG );
+
+ org.apache.log.Logger lmLogger =
+ Hierarchy.getDefaultHierarchy().getLoggerFor( lmLoggerName );
+ lmLogger.setPriority( Priority.getPriorityForName(
+ loggerManagerConfig.getAttribute( "log-level", "DEBUG" ) ) );
+
+ // Setup the Logger Manager
+ LogKitLoggerManager logManager = new LogKitLoggerManager(
+ logPrefix, Hierarchy.getDefaultHierarchy(),
+ new LogKitLogger( lmDefaultLogger ), new LogKitLogger(
lmLogger ) );
logManager.contextualize( rootContext );
logManager.configure( loggerManagerConfig );
@@ -774,8 +832,8 @@
{
// Should we set one up?
// Try to get a configuration for it...
- Configuration profilerConfig = getConfiguration(
INSTRUMENT_MANAGER_CONFIGURATION, INSTRUMENT_MANAGER_CONFIGURATION_URI );
- if( profilerConfig == null )
+ Configuration instrumentConfig = getConfiguration(
INSTRUMENT_MANAGER_CONFIGURATION, INSTRUMENT_MANAGER_CONFIGURATION_URI );
+ if( instrumentConfig == null )
{
// No config.
// Does the parent supply a logger manager?
@@ -790,30 +848,25 @@
{
}
- profilerConfig = EMPTY_CONFIG;
+ instrumentConfig = EMPTY_CONFIG;
}
+
+ // Get the context Logger Manager
+ LoggerManager loggerManager = (LoggerManager)childContext.get(
LOGGER_MANAGER );
+ // Get the logger for the instrument manager
+ Logger imLogger = loggerManager.getLoggerForCategory(
+ instrumentConfig.getAttribute( "logger", "system.instrument"
) );
+
+ // Set up the Instrument Manager
DefaultInstrumentManager instrumentManager = new
DefaultInstrumentManager();
- instrumentManager.enableLogging( getLogger() );
- instrumentManager.configure( profilerConfig );
+ instrumentManager.enableLogging( imLogger );
+ instrumentManager.configure( instrumentConfig );
instrumentManager.initialize();
assumeOwnership( instrumentManager );
childContext.put( INSTRUMENT_MANAGER, instrumentManager );
- }
- finally
- {
- // Since we now have a LoggerManager, we can update the
this.logger field
- // if it is null and start logging to the "right" logger.
-
- if( this.logger == null )
- {
- getLogger().info( "Switching to default Logger provided by
LoggerManager." );
-
- LoggerManager loggerManager =
(LoggerManager)childContext.get( LOGGER_MANAGER );
- this.logger = loggerManager.getDefaultLogger();
- }
}
}
}
1.14 +11 -2
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util/ExcaliburRoleManager.java
Index: ExcaliburRoleManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util/ExcaliburRoleManager.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- ExcaliburRoleManager.java 6 Aug 2002 19:41:19 -0000 1.13
+++ ExcaliburRoleManager.java 7 Aug 2002 04:55:55 -0000 1.14
@@ -52,6 +52,8 @@
import java.util.Collections;
import java.util.HashMap;
+import org.apache.avalon.framework.activity.Initializable;
+
/**
* The Excalibur Role Manager is used for Excalibur Role Mappings. All of
* the information is hard-coded.
@@ -63,6 +65,7 @@
*/
public class ExcaliburRoleManager
extends AbstractRoleManager
+ implements Initializable
{
/**
* Default constructor--this RoleManager has no parent.
@@ -92,7 +95,13 @@
public ExcaliburRoleManager( RoleManager parent, ClassLoader loader )
{
super( parent, loader );
-
+ }
+
+ /**
+ * Initialize the role manager.
+ */
+ public void initialize()
+ {
HashMap shorts = new HashMap( 10 );
HashMap classes = new HashMap( 10 );
HashMap handlers = new HashMap( 10 );
1.11 +13 -1
jakarta-avalon-excalibur/fortress/src/test/org/apache/excalibur/fortress/util/test/ConfigurableRoleManagerTestCase.java
Index: ConfigurableRoleManagerTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/test/org/apache/excalibur/fortress/util/test/ConfigurableRoleManagerTestCase.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ConfigurableRoleManagerTestCase.java 6 Aug 2002 19:53:39 -0000
1.10
+++ ConfigurableRoleManagerTestCase.java 7 Aug 2002 04:55:55 -0000
1.11
@@ -50,7 +50,10 @@
package org.apache.excalibur.fortress.util.test;
import junit.framework.TestCase;
+
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.apache.avalon.framework.logger.Logger;
import org.apache.excalibur.fortress.util.ConfigurableRoleManager;
/**
@@ -65,12 +68,16 @@
public class ConfigurableRoleManagerTestCase
extends TestCase
{
+ Logger m_logger;
+
/**
* Default constructor--this RoleManager has no parent.
*/
public ConfigurableRoleManagerTestCase( String name )
{
super( name );
+
+ m_logger = new ConsoleLogger( ConsoleLogger.LEVEL_INFO );
}
/**
@@ -81,6 +88,7 @@
{
DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder();
ConfigurableRoleManager roles = new ConfigurableRoleManager( null,
this.getClass().getClassLoader() );
+ roles.enableLogging( m_logger );
roles.configure( builder.build( this.getClass().getClassLoader()
.getResourceAsStream(
"org/apache/excalibur/fortress/test/ContainerProfile.roles" ) ) );
@@ -106,6 +114,7 @@
{
DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder();
ConfigurableRoleManager roles = new ConfigurableRoleManager( null,
this.getClass().getClassLoader() );
+ roles.enableLogging( m_logger );
roles.configure( builder.build( this.getClass().getClassLoader()
.getResourceAsStream(
"org/apache/excalibur/fortress/test/ContainerProfile.roles" ) ) );
@@ -131,6 +140,7 @@
{
DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder();
ConfigurableRoleManager roles = new ConfigurableRoleManager( null,
this.getClass().getClassLoader() );
+ roles.enableLogging( m_logger );
roles.configure( builder.build( this.getClass().getClassLoader()
.getResourceAsStream(
"org/apache/excalibur/fortress/test/ContainerProfile.roles" ) ) );
@@ -156,6 +166,7 @@
{
DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder();
ConfigurableRoleManager roles = new ConfigurableRoleManager( null,
this.getClass().getClassLoader() );
+ roles.enableLogging( m_logger );
roles.configure( builder.build( this.getClass().getClassLoader()
.getResourceAsStream(
"org/apache/excalibur/fortress/test/ContainerProfile.roles" ) ) );
@@ -189,6 +200,7 @@
{
DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder();
ConfigurableRoleManager roles = new ConfigurableRoleManager( null,
this.getClass().getClassLoader() );
+ roles.enableLogging( m_logger );
roles.configure( builder.build( this.getClass().getClassLoader()
.getResourceAsStream(
"org/apache/excalibur/fortress/test/ContainerProfile.roles" ) ) );
1.13 +17 -1
jakarta-avalon-excalibur/fortress/src/test/org/apache/excalibur/fortress/util/test/ExcaliburRoleManagerTestCase.java
Index: ExcaliburRoleManagerTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/test/org/apache/excalibur/fortress/util/test/ExcaliburRoleManagerTestCase.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- ExcaliburRoleManagerTestCase.java 6 Aug 2002 19:53:39 -0000 1.12
+++ ExcaliburRoleManagerTestCase.java 7 Aug 2002 04:55:55 -0000 1.13
@@ -50,6 +50,9 @@
package org.apache.excalibur.fortress.util.test;
import junit.framework.TestCase;
+
+import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.apache.avalon.framework.logger.Logger;
import org.apache.excalibur.fortress.util.ExcaliburRoleManager;
/**
@@ -64,6 +67,7 @@
public class ExcaliburRoleManagerTestCase
extends TestCase
{
+ Logger m_logger;
boolean m_informixClassExists = false;
/**
@@ -82,6 +86,8 @@
{
m_informixClassExists = false;
}
+
+ m_logger = new ConsoleLogger( ConsoleLogger.LEVEL_INFO );
}
/**
@@ -91,6 +97,8 @@
throws Exception
{
ExcaliburRoleManager roles = new ExcaliburRoleManager( null,
this.getClass().getClassLoader() );
+ roles.enableLogging( m_logger );
+ roles.initialize();
assertEquals(
roles.getClassForName( "cache" ),
@@ -156,6 +164,8 @@
throws Exception
{
ExcaliburRoleManager roles = new ExcaliburRoleManager( null,
this.getClass().getClassLoader() );
+ roles.enableLogging( m_logger );
+ roles.initialize();
assertEquals(
roles.getNameForClass( Class.forName(
"org.apache.excalibur.cache.impl.DefaultCache" ) ),
@@ -221,6 +231,8 @@
throws Exception
{
ExcaliburRoleManager roles = new ExcaliburRoleManager( null,
this.getClass().getClassLoader() );
+ roles.enableLogging( m_logger );
+ roles.initialize();
assertEquals(
roles.getRoleForClass( Class.forName(
"org.apache.excalibur.cache.impl.DefaultCache" ) ),
@@ -286,6 +298,8 @@
throws Exception
{
ExcaliburRoleManager roles = new ExcaliburRoleManager( null,
this.getClass().getClassLoader() );
+ roles.enableLogging( m_logger );
+ roles.initialize();
Class[] classes = roles.getClassesForRole(
"org.apache.excalibur.cache.Cache" );
@@ -371,6 +385,8 @@
throws Exception
{
ExcaliburRoleManager roles = new ExcaliburRoleManager( null,
this.getClass().getClassLoader() );
+ roles.enableLogging( m_logger );
+ roles.initialize();
assertEquals(
roles.getHandlerClassForClass( Class.forName(
"org.apache.excalibur.cache.impl.DefaultCache" ) ),
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>