org.apache.avalon.excalibur.logger
Class AbstractLoggerManager

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

public abstract class AbstractLoggerManager
extends java.lang.Object
implements 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
protected  java.util.Map m_loggers
          Map for name to logger mapping.
protected  java.lang.String m_prefix
          The root logger to configure
 
Fields inherited from interface org.apache.avalon.excalibur.logger.LoggerManager
ROLE
 
Constructor Summary
AbstractLoggerManager(java.lang.String prefix, java.lang.String switchTo, Logger defaultLoggerOverride)
          Initializes AbstractLoggerManager.
 
Method Summary
protected abstract  Logger doGetLoggerForCategory(java.lang.String fullCategoryName)
          Actually create a logger wrapping underlying logger backed implementation for a give category.
 void enableLogging(Logger fallbackLogger)
          Accept the logger we shall use as the initial and the fallback logger.
 Logger getDefaultLogger()
          Retruns the logger for the "" category.
protected  Logger getLogger()
          Derived LoggerManager implementations should obtain a logger to log their own messages via this call.
 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

Constructor Detail

AbstractLoggerManager

public AbstractLoggerManager(java.lang.String prefix,
                             java.lang.String switchTo,
                             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 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(Logger fallbackLogger)
Accept the logger we shall use as the initial and the fallback logger.

Specified by:
enableLogging in interface LogEnabled
Parameters:
fallbackLogger - the logger. Must not be null.

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 Logger getDefaultLogger()
Retruns the logger for the "" category.

Specified by:
getDefaultLogger in interface LoggerManager

doGetLoggerForCategory

protected abstract 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 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


Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.