Access keys

LoggerHierarchy

Kind of class: class
Inherits from: BasicClass
Implements:
Author: Simon Wacker
Classpath: org.as2lib.env.log.repository.LoggerHierarchy
File last modified: Friday, 01 July 2005, 19:57:42
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 org.as2lib.env.log.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.

Constructor

LoggerHierarchy

function LoggerHierarchy (
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 org.as2lib.env.log.logger.RootLogger with name "root" and log level
ALL will be used instead.

Parameters:
root:
the root of the hierarchy

Instance methods

addLogger

function addLogger (
Adds a new logger to this hierarchical repository.

The logger is automatically integrated into the hierarchy.

Parameters:
logger:
the logger to add to this hierarchy
Throws:
org.as2lib.env.except.IllegalArgumentException if 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

getDefaultLoggerFactory

function getDefaultLoggerFactory (
Returns either the factory set via setDefaultLoggerFactory or the
default one.

The default factory returns instances of type
org.as2lib.env.log.logger.SimpleHierarchicalLogger.

Returns:
the factory used as default

getLogger

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:
name:
the name of the logger to obtain
Returns:
the logger corresponding to the name

getLoggerByFactory

function getLoggerByFactory (
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:
name:
the name of the logger to return
Returns:
the logger appropriate to the passed-in name

getRootLogger

function getRootLogger (
Void) : Logger
Returns the root logger of this hierarchy.
Returns:
the root logger of this hierarchy

setDefaultLoggerFactory

function setDefaultLoggerFactory (
defaultLoggerFactory:ConfigurableHierarchicalLoggerFactory) : Void
Sets the factory used to obtain loggers that have not been set manually before.
Parameters:
defaultLoggerFactory:
the factory to use as default