Class org.as2lib.env.log.repository.DynamicLoggerRepository

org.as2lib.core.BasicClass
   +--org.as2lib.env.log.repository.DynamicLoggerRepository

Implemented Interfaces

LoggerRepository

Description

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 LogManager#setLoggerRepository method. You can then use the static 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!"); }

Method Index

new DynamicLoggerRepository()

getLogger(), getLoggerFactory(), setLoggerFactory()

Inherited from BasicClass

toString()

Constructor Detail

DynamicLoggerRepository

public 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

Method Detail

getLoggerFactory

public function getLoggerFactory(Void):LoggerFactory

Returns the set logger factory.

Return

the set logger factory

setLoggerFactory

public 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

loggerFactorythe new logger factory

getLogger

public 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

namethe name of the logger to return

Return

the logger appropriate to the passed-in name

Specified By

getLogger() in org.as2lib.env.log.LoggerRepository