Following Peter's suggestion and my need to use log4j as the logger for my components (with ExcaliburComponentManager), I have modified the excalibur component.* classes to support other loggers. I'm still testing if it works but your mail on this subject prompted this early response.
Basically I have made almot all the classes implement LogEnabled (ComponentManager, ComponentHandler and ComponentFactory) and make sure the manager initializes the log eanbled Logger for the handler and the handler for the factory so that we have in the factory a valid org.apache.avalon.framework.Logger object. The biggest change I have made is in the factory where I have added a makeLogEnabledLogger() which creates a logger implementation for the component, based on the type of logger from the factory. Thus, if you initially write : manager.enableLogging ( new Log4JLogger(Category.getInstance("...."))); then, the components that implement LogEnabled will get a Log4JLogger. Writing this, I just realised that I forgot to take into account the case were the user would not have called enableLogging on ExcaliburComponentManager. We will simply need to add this case to makeLogEnabledLogger and default to logkit. In order to be able to compile even without log4j, I have used reflection to create a log4j logger. I have not paid attention to performance in this implementation and it can be improved performance wise. At this point, I wanted to verify if it would work and wanted to get your feedback. As I said to Peter, I'm on a production project that has been going on for a while and which has standardised on log4j and they don't want to change. However, I'd like to bring in avalon, mainly as a demonstrator of how to code properly (and so that unit tests can be easily written for components using mock objects). I have the option of using the modifed component.* package but I would of course like to benefit from excalibur's modifications so I would of course prefer if it could be quickly included within the excalibur codebase. I am willing to help improve this first implementation if you agree on principle. As you are moving towards neutral Logger anyway, it seems to be inline with excalibur's future. Thoughts ? Thanks -Vincent Note: I have not looked in detail in the excalibur sources so I am not familiar to any problem my changes could have introduced for existing components. Is there a full unit tests suite that I could run and where can I find the requirements/instructions for running it (link with environment, ...) ? Any mock object tests ? ----- Original Message ----- From: "Berin Loritsch" <[EMAIL PROTECTED]> To: "Avalon Developers List" <avalon-dev@jakarta.apache.org> Sent: Wednesday, November 28, 2001 1:35 PM Subject: Re: Logging, LogKit, JDK1.4 Logging ... > Bachran, Michael wrote: > > > Hi everybody, > > > > Unfortunately I missed the invention of the LogEnabled stuff? > > > > Currently I am using the Framework along with the ExcaliburComponentManager > > (ECM) (Release 4.0). Along with the ECM comes LogKit. > > As the project started using Log4J I am planning to shift to LogKit now to > > get rid of one of two loggers. > > > > I am currently wondering if LogEnabled will simply replace Loggable (same > > for abstract classes) and if this has something to do with shifting to > > compatibility with the upcomming JDK1.4 Logging API. > > I also want to use the LogKitManagement along with LogKit. > > At least I would like to know if the interface is stable or I should wait > > with shifting till the changes have been applied. > > > Rest easy Michael. > > The LogEnabled and Logger interfaces is a straight replacement for the > Loggable interface. The difference is that you are now not _tied_ at the > framework level. The ExcaliburComponentManager is still LogKit centric, > and will remain so for a while. > > The interface for the Framework Logger interface is exactly the same as > the public portion of the LogKit interface. Our first loyalty is to the Avalon > LogKit package--although we do not want to alienate potential users who don't > want to use it. In the end, you now have a public interface that is consistent > no matter what Logging package you use. > > > > > -- > > "Those who would trade liberty for > temporary security deserve neither" > - Benjamin Franklin > > > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> > >
diff -r compnew/ComponentHandler.java compold/ComponentHandler.java 17d16 < import org.apache.avalon.framework.logger.LogEnabled; 32,35c31 < implements Initializable, Disposable, LogEnabled { < < /** The org.apache.avalon.framework.logger.Logger */ < protected org.apache.avalon.framework.logger.Logger m_logEnabledLogger; --- > implements Initializable, Disposable { 129,138d124 < < protected final org.apache.avalon.framework.logger.Logger getLogEnabledLogger() < { < return m_logEnabledLogger; < } < < public void enableLogging(final org.apache.avalon.framework.logger.Logger logger) < { < m_logEnabledLogger = logger; < } diff -r compnew/DefaultComponentFactory.java compold/DefaultComponentFactory.java 10,11d9 < import java.lang.reflect.Method; < import java.lang.reflect.Constructor; 28d25 < import org.apache.avalon.framework.CascadingException; 43c40 < implements ObjectFactory, ThreadSafe, LogEnabled --- > implements ObjectFactory, ThreadSafe 126c123 < ((LogEnabled)component).enableLogging( makeLogEnabledLogger(getLogEnabledLogger(), logger) ); --- > ((LogEnabled)component).enableLogging( new LogKitLogger( > m_logkit.getLogger( logger ) ) ); 222c219 < protected final org.apache.avalon.framework.logger.Logger getLogEnabledLogger() --- > protected org.apache.avalon.framework.logger.Logger getLogEnabledLogger() 224,240c221 < return m_logEnabledLogger; < } < < public void enableLogging(final org.apache.avalon.framework.logger.Logger logger) < { < m_logEnabledLogger = logger; < } < < /** < * @return a logger < */ < protected final org.apache.avalon.framework.logger.Logger makeLogEnabledLogger( < org.apache.avalon.framework.logger.Logger parentLogger, String category) throws Exception < { < org.apache.avalon.framework.logger.Logger componentLogger; < < if (parentLogger.getClass().getName().equals("org.apache.avalon.framework.logger.Log4JLogger")) --- > if ( null == m_logEnabledLogger ) 242,262c223 < try { < Class categoryClass = Class.forName("org.apache.log4j.Category"); < Method getInstanceMethod = categoryClass.getMethod("getInstance", new Class[] {String.class}); < Object categoryObject = getInstanceMethod.invoke(null, new Object[] {category}); < < Class log4jLoggerClass = parentLogger.getClass(); < Constructor log4jLoggerConstructor = log4jLoggerClass.getConstructor(new Class[] {categoryClass}); < componentLogger = (org.apache.avalon.framework.logger.Logger)log4jLoggerConstructor.newInstance(new Object[] {categoryObject}); < } < catch (Exception e) < { < throw new CascadingException("Failed to create Log4J logger for category [" + category + "]", e); < } < } < else if (parentLogger instanceof LogKitLogger) < { < componentLogger = new LogKitLogger( m_logkit.getLogger( category ) ); < } < else < { < throw new Exception("Log4JLogger and LogKitLogger are the only currently supported loggers"); --- > m_logEnabledLogger = new LogKitLogger( getLogger() ); 265c226 < return componentLogger; --- > return m_logEnabledLogger; 267,268c228 < < } \ No newline at end of file --- > } diff -r compnew/DefaultComponentHandler.java compold/DefaultComponentHandler.java 65,71d64 < public void enableLogging(final org.apache.avalon.framework.logger.Logger logger) < { < m_factory.enableLogging( logger ); < < super.enableLogging( logger ); < } < diff -r compnew/DefaultRoleManager.java compold/DefaultRoleManager.java 17d16 < import org.apache.avalon.framework.logger.LogEnabled; 31c30 < implements RoleManager, Configurable, LogEnabled --- > implements RoleManager, Configurable 45,47d43 < /** The org.apache.avalon.framework.logger.Logger */ < private org.apache.avalon.framework.logger.Logger m_logEnabledLogger; < 221,231d216 < < public void enableLogging(final org.apache.avalon.framework.logger.Logger logger) < { < m_logEnabledLogger = logger; < } < < protected final org.apache.avalon.framework.logger.Logger getLogEnabledLogger() < { < return m_logEnabledLogger; < } < diff -r compnew/ExcaliburComponentManager.java compold/ExcaliburComponentManager.java 28,29d27 < import org.apache.avalon.framework.logger.LogEnabled; < import org.apache.avalon.framework.logger.Logger; 49,50c47 < LogKitManageable, < LogEnabled --- > LogKitManageable 84,86d80 < /** The org.apache.avalon.framework.logger.Logger */ < private org.apache.avalon.framework.logger.Logger m_logEnabledLogger; < 292d285 < handler.enableLogging( getLogEnabledLogger() ); 357d349 < role_info.enableLogging( getLogEnabledLogger() ); 509d500 < handler.enableLogging( getLogEnabledLogger() ); 535d525 < handler.enableLogging( getLogEnabledLogger() ); 546,556d535 < < public void enableLogging(final org.apache.avalon.framework.logger.Logger logger) < { < m_logEnabledLogger = logger; < } < < protected final org.apache.avalon.framework.logger.Logger getLogEnabledLogger() < { < return m_logEnabledLogger; < } < diff -r compnew/PoolableComponentHandler.java compold/PoolableComponentHandler.java 76,82d75 < public void enableLogging(final org.apache.avalon.framework.logger.Logger logger) < { < m_factory.enableLogging( logger ); < < super.enableLogging( logger ); < } < diff -r compnew/ThreadSafeComponentHandler.java compold/ThreadSafeComponentHandler.java 71,80d70 < public void enableLogging(final org.apache.avalon.framework.logger.Logger logger) < { < if ( this.m_factory != null ) < { < m_factory.enableLogging( logger ); < } < < super.enableLogging( logger ); < } <
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>