org.apache.avalon.excalibur.logger.decorator
Class CachingDecorator

java.lang.Object
  extended by org.apache.avalon.excalibur.logger.decorator.LoggerManagerDecorator
      extended by org.apache.avalon.excalibur.logger.decorator.CachingDecorator
All Implemented Interfaces:
LoggerManager, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.activity.Startable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.logger.LogEnabled

public class CachingDecorator
extends LoggerManagerDecorator

This class implements LoggerManager interface by passing all the job to a wrapped LoggerManager, but the returened Loggers are cached. All operations of this class are synchronized via a single lock. As the LoggerManager is not expected to be a performance bottleneck probably this design will be good enough.

Since:
4.0
Version:
CVS $Revision: 1.3 $ $Date: 2004/03/10 13:54:50 $
Author:
Avalon Development Team

Field Summary
private  org.apache.avalon.framework.logger.Logger m_defaultLogger
          This variable caches the result of getDefaultLogger().
private  java.util.Map m_loggers
          Logger-s cache.
 
Fields inherited from class org.apache.avalon.excalibur.logger.decorator.LoggerManagerDecorator
m_loggerManager
 
Fields inherited from interface org.apache.avalon.excalibur.logger.LoggerManager
ROLE
 
Constructor Summary
CachingDecorator(LoggerManager loggerManager)
          Creates a CachingDecorator instance.
 
Method Summary
 org.apache.avalon.framework.logger.Logger getDefaultLogger()
          Return the default Logger.
 org.apache.avalon.framework.logger.Logger getLoggerForCategory(java.lang.String categoryName)
          Return the Logger for the specified category.
 
Methods inherited from class org.apache.avalon.excalibur.logger.decorator.LoggerManagerDecorator
configure, contextualize, dispose, enableLogging, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_loggers

private final java.util.Map m_loggers
Logger-s cache. All access synchronized( m_loggers ).


m_defaultLogger

private org.apache.avalon.framework.logger.Logger m_defaultLogger
This variable caches the result of getDefaultLogger(). This class will treat getDefaultLogger() and getLoggerForCategory("") on our wrapped LoggerManager as being potentially different, although all of the existing adapters probably return the same Logger for both. Access synchronized( this );

Constructor Detail

CachingDecorator

public CachingDecorator(LoggerManager loggerManager)
Creates a CachingDecorator instance.

Method Detail

getLoggerForCategory

public org.apache.avalon.framework.logger.Logger getLoggerForCategory(java.lang.String categoryName)
Return the Logger for the specified category.

Specified by:
getLoggerForCategory in interface LoggerManager
Overrides:
getLoggerForCategory in class LoggerManagerDecorator

getDefaultLogger

public org.apache.avalon.framework.logger.Logger getDefaultLogger()
Return the default Logger. Although it is expected that the wrapped loggerManager will return the same as getLoggerForCategory("") we cache the value separtely.

Specified by:
getDefaultLogger in interface LoggerManager
Overrides:
getDefaultLogger in class LoggerManagerDecorator