org.as2lib.core.BasicClass +--org.as2lib.env.log.repository.LoggerHierarchy
LoggerRepository
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.
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.
root | the root of the hierarchy |
public function getDefaultLoggerFactory(Void):ConfigurableHierarchicalLoggerFactory
Returns either the factory set via setDefaultLoggerFactory or the default one.
The default factory returns instances of type SimpleHierarchicalLogger.
the factory used as default
public function setDefaultLoggerFactory(defaultLoggerFactory:ConfigurableHierarchicalLoggerFactory):Void
Sets the factory used to obtain loggers that have not been set manually before.
defaultLoggerFactory | the factory to use as default |
public function getRootLogger(Void):Logger
Returns the root logger of this hierarchy.
the root logger of this hierarchy
public function addLogger(logger:ConfigurableHierarchicalLogger):Void
Adds a new logger to this hierarchical repository.
The logger is automatically integrated into the hierarchy.
logger | the logger to add to this hierarchy |
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
|
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
.
name | the name of the logger to obtain |
the logger corresponding to the name
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.
name | the name of the logger to return |
the logger appropriate to the passed-in name