Class org.as2lib.env.log.repository.LoggerHierarchy

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

Implemented Interfaces

LoggerRepository

Description

LoggerHierarchy organizes loggers in a hierarchical structure.

It works only with loggers that are capable of acting properly in a hierarchy. These loggers must implement the ConfigurableHierarchicalLogger interface.

The names of the loggers must be fully qualified and the differnt parts of the preceding structure/path must be separated by periods.

This repository takes care that the parents of all loggers are correct and updates them if necessary. The hierarchical loggers themselves are responsible of obtaining the level and handlers from its parents if necessary and desired.

Example: var repository:LoggerHierarchy = new LoggerHierarchy(); LogManager.setLoggerRepository(repository); var traceLogger:SimpleHierarchicalLogger = new SimpleHierarchicalLogger("org.as2lib"); traceLogger.addHandler(new TraceHandler()); repository.addLogger(traceLogger); // in some other class or something var myLogger:Logger = LogManager.getLogger("org.as2lib.mypackage.MyClass"); myLogger.warning("Someone did something he should not do.");

The message is traced because the namespace of myLogger is the same as the one of traceLogger. You can of course add multiple handlers to one logger and also multiple loggers to different namespaces.

Method Index

new LoggerHierarchy()

addLogger(), getDefaultLoggerFactory(), getLogger(), getLoggerByFactory(), getRootLogger(), setDefaultLoggerFactory()

Inherited from BasicClass

toString()

Constructor Detail

LoggerHierarchy

public function LoggerHierarchy(root:ConfigurableHierarchicalLogger)

Constructs a new LoggerHierarchy instance.

Registers the root logger with name "root" if the root's getName method returns null or undefined. Otherwise it will be registered with the name returned by the root's getName method.

If the passed-in root is null or undefined an instance of type RootLogger with name "root" and log level ALL will be used instead.

Parameters

rootthe root of the hierarchy

Method Detail

getDefaultLoggerFactory

public function getDefaultLoggerFactory(Void):ConfigurableHierarchicalLoggerFactory

Returns either the factory set via setDefaultLoggerFactory or the default one.

The default factory returns instances of type SimpleHierarchicalLogger.

Return

the factory used as default

setDefaultLoggerFactory

public function setDefaultLoggerFactory(defaultLoggerFactory:ConfigurableHierarchicalLoggerFactory):Void

Sets the factory used to obtain loggers that have not been set manually before.

Parameters

defaultLoggerFactorythe factory to use as default

getRootLogger

public function getRootLogger(Void):Logger

Returns the root logger of this hierarchy.

Return

the root logger of this hierarchy

addLogger

public function addLogger(logger:ConfigurableHierarchicalLogger):Void

Adds a new logger to this hierarchical repository.

The logger is automatically integrated into the hierarchy.

Parameters

loggerthe logger to add to this hierarchy

Throws

IllegalArgumentExceptionif the passed-in logger is null or undefined or if the passed-in logger's getName method returns null or undefined or if a logger with the logger's name is already in use

getLogger

public function getLogger(name:String):Logger

Returns the logger appropriate to the given name.

The name can exist of a path as well as the actual specifier, for example org.as2lib.core.BasicClass. In case no logger instance has been put for the passed-in name a new will be created by the set factory, that by default obtains all its configuration from the parent logger.

null will be returned if passed-in name is null or undefined.

Parameters

namethe name of the logger to obtain

Return

the logger corresponding to the name

Specified By

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

getLoggerByFactory

public function getLoggerByFactory(name:String, factory:ConfigurableHierarchicalLoggerFactory):Logger

Returns the logger corresponding to the passed-in name.

If a logger with the passed-in name is not explicitely registered the logger returned by the factory is registered with the passed-in name, integrated in the hierarchy and returned.

The name can exist of a path as well as the actual specifier, for example org.as2lib.core.BasicClass. In case no logger instance has been put for the passed-in name a new will be created by the set factory, that by default obtains all its configuration from the parent logger.

null will be returned if the passed-in name is null or undefined.

If the passed-in factory is null or undefined the default one will be used.

Parameters

namethe name of the logger to return

Return

the logger appropriate to the passed-in name