org.objectledge.logging
Class LoggerFactory

java.lang.Object
  extended by org.objectledge.logging.LoggerFactory
All Implemented Interfaces:
CustomizedComponentProvider

public class LoggerFactory
extends Object
implements CustomizedComponentProvider

Provides Logger objects to the components being initialized using Log4J.

Logger factory plugs into the container using component customization mechanism, and provides components that declare a dependency on a DNA Logger (using a org.jcontainer.dna.Logger component parameter) with an initialized and ready to go logger instance.

The default implementation creates Log4j loggers, but it can be easily extended to work with any other type of logger compatible with DNA.

The LoggerFactory component has the ability to transparently replace the logger used by a component with another logger. (This is done using Pico's ImplementationHidingComponentAdapter). This might be useful for run-time administraiton, especially in case of Logger objects that are immutable.

Version:
$Id: LoggerFactory.java,v 1.18 2005/10/09 19:12:04 rafal Exp $
Author:
rafal@caltha.pl

Field Summary
private  org.picocontainer.MutablePicoContainer loggerContainer
           
private  LoggingConfigurator loggingConfigurator
           
 
Constructor Summary
LoggerFactory(LoggingConfigurator loggingConfigurator)
          Creates a new instance of Factory and installs apropriate component adapter.
 
Method Summary
protected  String getComponentMarker(Object key)
          Returns a marker for the component (used as key in the logger container).
 Class getCustomizedComponentImplementation()
          Returns the type of the customized components.
 Object getCustomizedComponentInstance(org.picocontainer.PicoContainer container, Object componentKey, Class componentImplementaion)
          Returns a customized component instance.
 org.jcontainer.dna.Logger getLogger(Object key)
          Returns a logger for the specified component.
 void setLogger(Object key, org.jcontainer.dna.Logger logger)
          Sets the logger for the specified component.
 void verify(org.picocontainer.PicoContainer container)
          Verifies if the customized component can be instantiated using the dependencies present in the associated container.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

loggingConfigurator

private final LoggingConfigurator loggingConfigurator

loggerContainer

private final org.picocontainer.MutablePicoContainer loggerContainer
Constructor Detail

LoggerFactory

public LoggerFactory(LoggingConfigurator loggingConfigurator)
Creates a new instance of Factory and installs apropriate component adapter.

We depend LoggingConfigurator to make sure that logging is configured before we create any logs.

Parameters:
loggingConfigurator - the LoggingConfigurator.
Method Detail

getLogger

public org.jcontainer.dna.Logger getLogger(Object key)
Returns a logger for the specified component.

Parameters:
key - the component key.
Returns:
the logger.

setLogger

public void setLogger(Object key,
                      org.jcontainer.dna.Logger logger)
Sets the logger for the specified component.

Parameters:
key - the component key.
logger - the logger.

getCustomizedComponentInstance

public Object getCustomizedComponentInstance(org.picocontainer.PicoContainer container,
                                             Object componentKey,
                                             Class componentImplementaion)
                                      throws org.picocontainer.PicoInitializationException,
                                             org.picocontainer.PicoIntrospectionException,
                                             UnsupportedKeyTypeException
Returns a customized component instance.

Specified by:
getCustomizedComponentInstance in interface CustomizedComponentProvider
Parameters:
container - the container.
componentKey - requesting component's key.
componentImplementaion - requesting component's implmenetation class.
Returns:
customized component.
Throws:
org.picocontainer.PicoInitializationException - if the customized component cannot be initialized.
org.picocontainer.PicoIntrospectionException - if the customized component cannot be initialized.
UnsupportedKeyTypeException - if the componentKey has unsupported type.

getCustomizedComponentImplementation

public Class getCustomizedComponentImplementation()
Returns the type of the customized components.

Specified by:
getCustomizedComponentImplementation in interface CustomizedComponentProvider
Returns:
the type of the customized components.

verify

public void verify(org.picocontainer.PicoContainer container)
            throws org.picocontainer.PicoVerificationException
Verifies if the customized component can be instantiated using the dependencies present in the associated container.

Specified by:
verify in interface CustomizedComponentProvider
Parameters:
container - the container.
Throws:
org.picocontainer.PicoVerificationException - if the container does not contain required dependencies.

getComponentMarker

protected String getComponentMarker(Object key)
Returns a marker for the component (used as key in the logger container).

Parameters:
key - reqesting component key.
Returns:
key for the logger.


Copyright © 2003-2006 objectledge.org. All Rights Reserved.