Class org.as2lib.env.log.LogManager

org.as2lib.core.BasicClass
   +--org.as2lib.env.log.LogManager

Description

LogManager is the core access point of the As2lib Logging API.

You use it to set the underlying repository that stores and releases loggers and to obtain a logger according to a logger's name of the repository.

The repository must be set before anything else using this class as access point to obtain loggers. There is no default repository.

This class could be used as follows with a non-singleton repository. Note that you can of course also use any other kind of logger repository. // configuration: when setting everything up var loggerHierarchy:LoggerHierarchy = new LoggerHierarchy(); var traceLogger:SimpleHierarchicalLogger = new SimpleHierarchicalLogger("org.mydomain"); traceLogger.addHandler(new TraceHandler()); loggerHierarchy.addLogger(traceLogger); LogManager.setLoggerRepository(loggerHierarchy); // usage: in the class org.mydomain.MyClass var myLogger:Logger = LogManager.getLogger("org.mydomain.MyClass"); if (myLogger.isInfoEnabled()) { myLogger.info("This is an informative log message."); }

If you have one logger that shall always be returned you can use the convenience method setLogger that does all the work with the repository for you. // configuration: when setting everything up var traceLogger:SimpleLogger = new SimpleLogger(); traceLogger.addHandler(new TraceHandler()); LogManager.setLogger(traceLogger); // usage: in the class org.mydomain.MyClass var myLogger:Logger = LogManager.getLogger("org.mydomain.MyClass"); if (myLogger.isInfoEnabled()) { myLogger.info("This is an informative log message."); }

Method Index

getLogger(), getLoggerRepository(), setLogger(), setLoggerRepository()

Inherited from BasicClass

toString()

Method Detail

getLogger

static public function getLogger(loggerName:String):Logger

Returns the logger according the passed-in loggerName.

Uses the set logger repository to receive the logger that is returned.

null is returned if the logger repository returns null or undefined.

Parameters

loggerNamethe name of the logger to return

Return

the logger according to the passed-in name

setLogger

static public function setLogger(logger:Logger):Void

Sets the logger that is returned on calls to the getLogger method.

This method actually sets a singleton repository via the static setLoggerRepository that always returns the passed-in logger and ignores the name.

You could also set the repository by hand, this is just an easier way of doing it if you always want the same logger to be returned.

Parameters

loggerthe logger to return on calls to the method

getLoggerRepository

static public function getLoggerRepository(Void):LoggerRepository

Reutrns the logger repository set via setLoggerRepository.

There is no default logger repository, so you must set it before anything else.

Return

the set logger repository

setLoggerRepository

static public function setLoggerRepository(loggerRepository:LoggerRepository):Void

Sets a new repositroy returned by getLoggerRepository.

The getLogger method uses this repository to obtain the logger for the passed-in name.

Parameters

loggerRepositorythe new logger repository