Access keys

DynamicLoggerRepository

Kind of class: class
Inherits from: BasicClass
Implements:
Author: Simon Wacker
Classpath: org.as2lib.env.log.repository.DynamicLoggerRepository
File last modified: Friday, 01 July 2005, 19:57:42
DynamicLoggerRepository is used to obtain loggers.

The actual class of these loggers is determined by you at runtime. You can
therefor either use the constructors logger class argument or the
setLoggerFactory method.

This repository is very performant. What it does is quite simple. It only
instantiates logger instances passing-in the given name, stores these instances
by name for retrieval later on and returns them.

When working with logger repositories you normally store them in the log
manager using the static org.as2lib.env.log.LogManager.setLoggerRepository method. You can
then use the static org.as2lib.env.log.LogManager.getLogger method to obtain loggers from
the set repository.

Example:

// configuration: on system start-up
var repository:LoggerRepository = new DynamicLoggerRepository(MyLogger);
LogManager.setLoggerRepository(repository);
// usage: in the org.mydomain.MyClass class
var myLogger:Logger = LogManager.getLogger("org.mydomain.MyClass");
if (myLogger.isWarningEnabled()) {
    myLogger.warning("Pay attention please!");
}

Summary

Constructor

DynamicLoggerRepository

function DynamicLoggerRepository (
loggerClass:Function)
Constructs a new DynamicLoggerRepository instance.

If you do not pass a loggerClass you must set the logger factory via
the setLoggerFactory method. Otherwise the logger returned by
getLogger will always be null.

The logger is wrapped into a factory and the factory is set. The factory
then instantiates the logger class passing-in the name of the logger on calls
to getLogger.

Already received loggers are cached by name. Thus there exists only one
logger instance per name.

Parameters:
loggerClass:
(optional) the class to create loggers of

Instance methods

getLogger

function getLogger (
name:String) : Logger
Returns a pre-configured logger for the passed-in name.

A new logger is created for names to which no logger has been assigned yet.
The new logger is configured with the name, either by the custom
factory or by the default one, which passes the name as parameter to
the constructor of the logger class. The logger is then cached by name and
returned for usage.

null will be returned if:

  • No logger factory has been set.
  • The set logger factory returns null or undefined.
«
Parameters:
name:
the name of the logger to return
Returns:
the logger appropriate to the passed-in name

getLoggerFactory

function getLoggerFactory (
Returns the set logger factory.
Returns:
the set logger factory

setLoggerFactory

function setLoggerFactory (
loggerFactory:LoggerFactory) : Void
Sets a new logger factory.

This logger factory is used to create loggers for given names, that are
returned by the getLogger method.

Parameters:
loggerFactory:
the new logger factory