org.apache.avalon.excalibur.logger
Class AbstractLoggerManager

java.lang.Object
  extended by org.apache.avalon.excalibur.logger.AbstractLoggerManager
All Implemented Interfaces:
LoggerManager, org.apache.avalon.framework.logger.LogEnabled
Direct Known Subclasses:
Log4JLoggerManager, LogKitLoggerManager

public abstract class AbstractLoggerManager
extends java.lang.Object
implements org.apache.avalon.framework.logger.LogEnabled, LoggerManager

This abstract class implements LogEnabled. A derived class is expected to obtain a logger via getLogger() and live with it. The Logger supplied via enableLogging will be used both as the "initial" and as the "fallback" logger.

See LoggerSwitch for more details.

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

Field Summary
private  org.apache.avalon.framework.logger.Logger m_defaultLoggerOverride
          The logger used to be returned from getDefaultLogger() and getLoggerForCategory(""), if one has been forcibly set via a constructor.
private  boolean m_enableLoggingInvoked
          safeguards against double enableLogging() invocation.
private  org.apache.avalon.framework.logger.Logger m_logger
          Always equals to m_switch.get()
protected  java.util.Map m_loggers
          Map for name to logger mapping.
protected  java.lang.String m_prefix
          The root logger to configure
private  boolean m_startInvoked
          safeguards against double start() invocation.
private  LoggerSwitch m_switch
          The object that wraps a swithing logger.
private  java.lang.String m_switchTo
          category we should switch our own loggin to on start().
 
Fields inherited from interface org.apache.avalon.excalibur.logger.LoggerManager
ROLE
 
Constructor Summary
AbstractLoggerManager(java.lang.String prefix, java.lang.String switchTo, org.apache.avalon.framework.logger.Logger defaultLoggerOverride)
          Initializes AbstractLoggerManager.
 
Method Summary
protected abstract  org.apache.avalon.framework.logger.Logger doGetLoggerForCategory(java.lang.String fullCategoryName)
          Actually create a logger wrapping underlying logger backed implementation for a give category.
 void enableLogging(org.apache.avalon.framework.logger.Logger fallbackLogger)
          Accept the logger we shall use as the initial and the fallback logger.
 org.apache.avalon.framework.logger.Logger getDefaultLogger()
          Retruns the logger for the "" category.
protected  org.apache.avalon.framework.logger.Logger getLogger()
          Derived LoggerManager implementations should obtain a logger to log their own messages via this call.
 org.apache.avalon.framework.logger.Logger getLoggerForCategory(java.lang.String categoryName)
          Retrieves a Logger from a category name.
 void start()
          Get a logger from ourselves and pass it to m_switch.
 void stop()
          Startable.stop() empty implementation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_loggers

protected final java.util.Map m_loggers
Map for name to logger mapping. This instance variable is protected (not privated) so that it may be pre-filled at configuration stage.


m_prefix

protected java.lang.String m_prefix
The root logger to configure


m_switch

private LoggerSwitch m_switch
The object that wraps a swithing logger. The switching logger itself for security reasons has no methods of controlling it, but its wrapping object has.


m_logger

private org.apache.avalon.framework.logger.Logger m_logger
Always equals to m_switch.get()


m_switchTo

private java.lang.String m_switchTo
category we should switch our own loggin to on start().


m_enableLoggingInvoked

private boolean m_enableLoggingInvoked
safeguards against double enableLogging() invocation.


m_startInvoked

private boolean m_startInvoked
safeguards against double start() invocation.


m_defaultLoggerOverride

private final org.apache.avalon.framework.logger.Logger m_defaultLoggerOverride
The logger used to be returned from getDefaultLogger() and getLoggerForCategory(""), if one has been forcibly set via a constructor.

Constructor Detail

AbstractLoggerManager

public AbstractLoggerManager(java.lang.String prefix,
                             java.lang.String switchTo,
                             org.apache.avalon.framework.logger.Logger defaultLoggerOverride)
Initializes AbstractLoggerManager.

Parameters:
prefix - the prefix to prepended to the category name on each invocation of getLoggerForCategory before passing the category name on to the underlying logging system (currently LogKit or Log4J).
switchTo - fuel for the start() method; if null start() will do nothing; if empty start() will switch to getLoggerForCategory("").
Method Detail

getLogger

protected org.apache.avalon.framework.logger.Logger getLogger()
Derived LoggerManager implementations should obtain a logger to log their own messages via this call. It is also safe to log messages about logging failures via this logger as it safeguards internally gainst recursion.


enableLogging

public void enableLogging(org.apache.avalon.framework.logger.Logger fallbackLogger)
Accept the logger we shall use as the initial and the fallback logger.

Specified by:
enableLogging in interface org.apache.avalon.framework.logger.LogEnabled

start

public void start()
Get a logger from ourselves and pass it to m_switch.


stop

public void stop()
Startable.stop() empty implementation.


getDefaultLogger

public final org.apache.avalon.framework.logger.Logger getDefaultLogger()
Retruns the logger for the "" category.

Specified by:
getDefaultLogger in interface LoggerManager

doGetLoggerForCategory

protected abstract org.apache.avalon.framework.logger.Logger doGetLoggerForCategory(java.lang.String fullCategoryName)
Actually create a logger wrapping underlying logger backed implementation for a give category. Bypasses the caching. Derived LoggerManager implementations should provide an implementation of this method.


getLoggerForCategory

public final org.apache.avalon.framework.logger.Logger getLoggerForCategory(java.lang.String categoryName)
Retrieves a Logger from a category name. Usually the category name refers to a configuration attribute name. If this LogKitManager does not have the match the default Logger will be returned and a warning is issued.

Specified by:
getLoggerForCategory in interface LoggerManager