Hello, Berin!

I have examined more closely what is in CVS and found that all
of the patch #11 is there - wow! I like that! I'm aware that
the value of my patches varies widely, and some are only
marginally usefull, still it honores my vanity :-)

Now, [Patch] #10.1 is still pending, meanwhile here goes one
more my (the very last?) pass over ContextManager.

------Patch #12----------
Files affected: ContextManager.java

removed unused
    ServiceManager m_manager;

remove
    double null-ing of RoleManager.ROLE in m_childContext

moved
    comment on RoleManager not being passed to Container
    to initializeServiceManager

wrapped
    severl lines to fit into 100 characters limit

made a first pass on teaching initializeLoggerManager to
create Log4JLoggerManager alternatively to LogKitLoggerManager

    as I haven't been advised any other way I have implemented
    two ways to detect it's a Log4J conf, not a LogKit one:

    <any-root-element version="log4j">

    (I've accidentially seen on users@ that this is used in Phoenix)

    <log4j:configuration>

    (looks like Log4J native configuration files look like this)

    Now, I'm sure that my section that really creates a Log4J logger
    manager is very weak: I've never really worked with logger
    managers in detail, neither am I familiar with Log4J beyond
    reading Log4J[Conf]LoggerManager.java. See the comments inline
    the code for more details on what I cosidere unimplemented there.
    I have also signed these comments with my name so that everyone
    knows that it's my ignorance not yours :-). Hope these comments
    will go away with time - I understand it's no good to have my
    humble ;-) name there.

    Nevertheless I consider it would be usefull to put in
    any support of Log4J into ContextManager and I believe
    that once it there someone who will actually use it
    will probably further develop it.

    No testcase available with the same reasoning.

    I hope that once (and if :-) this gets to the CVS or release
    cadidate probably

    Peter Severin <[EMAIL PROTECTED]>

    who has expressed interest in it and who has pushed me into
    this patch will help us to test this. Currently the code
    is totally untested - I do not "speak" Log4J :-(

WBR, Anton Tagunov

--- ContextManager.orig 2003-05-29 09:59:36.000000000 +0400
+++ ContextManager.java 2003-05-29 11:13:14.000000000 +0400
@@ -50,6 +50,7 @@
 package org.apache.avalon.fortress.util;
 
 import org.apache.avalon.excalibur.logger.LogKitLoggerManager;
+import org.apache.avalon.excalibur.logger.Log4JConfLoggerManager;
 import org.apache.avalon.excalibur.logger.LoggerManager;
 import org.apache.avalon.fortress.MetaInfoManager;
 import org.apache.avalon.fortress.RoleManager;
@@ -161,8 +162,6 @@
      */
     protected SourceResolver m_defaultSourceResolver;
 
-    protected ServiceManager m_manager;
-
     /**
      * The logger manager in use.
      * Either supplied via rootContext, or created locally.
@@ -292,7 +291,8 @@
         }
         catch ( ContextException ce )
         {
-            final Configuration containerConfig = getConfiguration( CONFIGURATION, 
CONFIGURATION_URI );
+            final Configuration containerConfig = 
+                    getConfiguration( CONFIGURATION, CONFIGURATION_URI );
 
             if ( containerConfig == null )
             {
@@ -551,10 +551,6 @@
          */
         if ( entryPresent( m_rootContext, RoleManager.ROLE ) )
         {
-            /* RoleManager is a compatibility mechanism to read in ECM roles files.  
The role manager will be wrapped
-             * by a MetaInfoManager.  So we hide the RoleManager here from the 
contaienr implementation.
-             */
-            m_childContext.put( RoleManager.ROLE, null );
             return (RoleManager) m_rootContext.get( RoleManager.ROLE );
         }
 
@@ -574,7 +570,8 @@
         }
 
         // Lookup the context class loader
-        final ClassLoader classLoader = (ClassLoader) m_rootContext.get( 
ClassLoader.class.getName() );
+        final ClassLoader classLoader = 
+                (ClassLoader) m_rootContext.get( ClassLoader.class.getName() );
 
         // Create a logger for the role manager
         final Logger rmLogger = m_loggerManager.getLoggerForCategory(
@@ -622,18 +619,21 @@
         }
         else
         {
-            final ClassLoader classLoader = (ClassLoader) m_rootContext.get( 
ClassLoader.class.getName() );
+            final ClassLoader classLoader = 
+                    (ClassLoader) m_rootContext.get( ClassLoader.class.getName() );
 
             if ( !rmSupplied )
             {
-                final FortressRoleManager newRoleManager = new FortressRoleManager( 
null, classLoader );
+                final FortressRoleManager newRoleManager = 
+                        new FortressRoleManager( null, classLoader );
                 newRoleManager.enableLogging( m_loggerManager.getLoggerForCategory( 
"system.roles" ) );
                 newRoleManager.initialize();
 
                 roleManager = newRoleManager;
             }
 
-            final ServiceMetaManager metaManager = new ServiceMetaManager( new 
Role2MetaInfoManager( roleManager ), classLoader );
+            final ServiceMetaManager metaManager = 
+                    new ServiceMetaManager( new Role2MetaInfoManager( roleManager ), 
classLoader );
 
             metaManager.enableLogging( m_loggerManager.getLoggerForCategory( 
"system.meta" ) );
             metaManager.initialize();
@@ -694,6 +694,10 @@
             manager.put( SourceResolver.ROLE, m_defaultSourceResolver );
         }
 
+        /**
+         * Role manager won't be passed here as it is now only
+         * an utility for reading ECM role files.
+         */
         manager.put( LoggerManager.ROLE, m_loggerManager );
         manager.put( Sink.ROLE, m_sink );
         manager.put( MetaInfoManager.ROLE, m_metaInfoManager );
@@ -816,42 +820,95 @@
         {
             // 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 );
+
+            boolean log4j = false;
+
             if ( loggerManagerConfig == null )
             {
                 // Create an empty configuration so that
                 // a default logger can be created.
                 loggerManagerConfig = EMPTY_CONFIG;
             }
+            else
+            {
+                /**
+                 * We rely on namespace handing being turned off in 
DefaultConfiguration
+                 * builder here. TODO: add code that test
+                 * root element for name "configuration" and for the correct Log4J
+                 * configuration namespace (not currently known to me - Anton Tagunov)
+                 * to survive if a namespace-enabled configuration has been passed to 
us.
+                 */
+                final String version = loggerManagerConfig.getAttribute( "version", 
null );
+                if ( "log4j".equals( version ) )
+                {
+                    log4j = true;
+                }
+                else if ( "log4j:configuration".equals( loggerManagerConfig.getName() 
) )
+                {
+                    log4j = true;
+                }
+            }
 
             // Resolve a name for the logger, taking the logPrefix into account
-            final String lmDefaultLoggerName = (String) m_rootContext.get( 
ContextManagerConstants.LOG_CATEGORY );
-            final String lmLoggerName = loggerManagerConfig.getAttribute( "logger", 
lmDefaultLoggerName + ".system.logkit" );
-
-            // Create the default logger for the Logger Manager.
-            final 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 );
-
-            // Create the logger for use internally by the Logger Manager.
-            final org.apache.log.Logger lmLogger =
-                    Hierarchy.getDefaultHierarchy().getLoggerFor( lmLoggerName );
-            lmLogger.setPriority( Priority.getPriorityForName(
-                    loggerManagerConfig.getAttribute( "log-level", "DEBUG" ) ) );
-
-            // Setup the Logger Manager
-            final LoggerManager logManager = new LogKitLoggerManager(
-                    lmDefaultLoggerName, Hierarchy.getDefaultHierarchy(),
-                    new LogKitLogger( lmDefaultLogger ), new LogKitLogger( lmLogger ) 
);
-            ContainerUtil.contextualize( logManager, m_rootContext );
-            ContainerUtil.configure( logManager, loggerManagerConfig );
-
-            assumeOwnership( logManager );
+            final String lmDefaultLoggerName = 
+                    (String) m_rootContext.get( ContextManagerConstants.LOG_CATEGORY 
);
+            final String lmLoggerName = loggerManagerConfig.getAttribute( "logger", 
+                    lmDefaultLoggerName + ( log4j ? ".system.log4j" : 
".system.logkit" ) );
+            
+            if ( log4j )
+            {
+                // this section totally not debuged, just written - Anton Tagunov
+                final Log4JConfLoggerManager logManager = new 
Log4JConfLoggerManager();
+                logManager.configure( loggerManagerConfig );
+                // Create the logger for use internally by the Logger Manager.
+                Logger lmLogger = logManager.getLoggerForCategory( lmLoggerName );
+                /**
+                 * We rely here on specifics of Log4JConfLoggerManager implementation:
+                 * enableLogging may be called _after_ configure.
+                 */
+                logManager.enableLogging( lmLogger );
+
+                /**
+                 * Now let's compare this immature section with the mature one
+                 * bellow: we haven't made sure the default logger is at DEBUG
+                 * priority level, we haven't considered log-level attribute
+                 * on the root element to set the priority of the logger
+                 * servicing Log4LoggerManager itself. Moreover we have
+                 * enableLogging called after configure on Log4ConfLoggerManager
+                 * which is potentially explosive. Conclusion: this section
+                 * is just a scetch and needs further work. - Anton Tagunov
+                 */
 
-            m_loggerManager = logManager;
+                m_loggerManager = logManager;
+            }
+            else // LogKitLoggerManager
+            {
+                // Create the default logger for the Logger Manager.
+                final 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 );
+            
+                // Create the logger for use internally by the Logger Manager.
+                final org.apache.log.Logger lmLogger =
+                        Hierarchy.getDefaultHierarchy().getLoggerFor( lmLoggerName );
+                lmLogger.setPriority( Priority.getPriorityForName(
+                        loggerManagerConfig.getAttribute( "log-level", "DEBUG" ) ) );
+
+                // Setup the Logger Manager
+                final LoggerManager logManager = new LogKitLoggerManager(
+                        lmDefaultLoggerName, Hierarchy.getDefaultHierarchy(),
+                        new LogKitLogger( lmDefaultLogger ), new LogKitLogger( 
lmLogger ) );
+                ContainerUtil.contextualize( logManager, m_rootContext );
+                ContainerUtil.configure( logManager, loggerManagerConfig );
+            
+                assumeOwnership( logManager );
+            
+                m_loggerManager = logManager;
+            }
         }
 
         // Since we now have a LoggerManager, we can update the this.logger field
@@ -889,7 +946,8 @@
         {
             // Should we set one up?
             // Try to get a configuration for it...
-            Configuration instrumentConfig = getConfiguration( 
INSTRUMENT_MANAGER_CONFIGURATION, INSTRUMENT_MANAGER_CONFIGURATION_URI );
+            Configuration instrumentConfig = getConfiguration( 
INSTRUMENT_MANAGER_CONFIGURATION, 
+                    INSTRUMENT_MANAGER_CONFIGURATION_URI );
             if ( instrumentConfig == null )
             {
                 // No config.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to