org.as2lib.core.BasicClass +--org.as2lib.env.log.logger.AbstractLogger +--org.as2lib.env.log.logger.SimpleHierarchicalLogger
SimpleHierarchicalLogger
is a simple implementation of the
ConfigurableLogger
and ConfigurableHierarchicalLogger
interfaces.
This logger is thus capable of functioning correctly in a hierarchy. It is
normally used with the LoggerHierarchy
repository.
The basic methods to write log messages are log, debug, info, warning and fatal.
The first thing to note is that you can log messages at different levels.
These levels are DEBUG
, INFO
, WARNING
, ERROR
and
FATAL
. Depending on what level has been set only messages at a given
level are logged. The levels are organized in a hierarchical manner. This means
if you set the log level to ALL
every messages is logged. If you set it
to ERROR
only messages at ERROR
and FATAL
level are
logged and so on. It is also possible to define your own set of levels. You can
therefor use the isEnabled and log methods. If you do not set
a log level the level of its parent is used to decide whether the message shall
be logged.
To do not waste unnecessary performance in constructing log messages that are not logged you can use the isEnabled, isDebugEnabled, isInfoEnabled, isWarningEnabled, isErrorEnabled and isFatalEnabled methods.
Note that the message does in neither case have to be a string. That means
you can pass-in messages and let the actual handler or logger decide how to
produce a string representation of the message. That is in most cases done by
using the toString
method of the specific message. You can use this
method to do not lose performance in cases where the message is not logged.
The actual logging is made by log handlers. To configure and access the
handlers of this logger you can use the methods addHandler,
removeHandler, removeAllHandlers and getAllHandlers.
There are a few pre-defined handlers for different output devices. Take a look
at the org.as2lib.env.log.handler
package for these. This logger does
not only use the handlers of itself but also the ones of its parents.
Note that advantage of this class's hierarchical support is not taken in the
following example. Take a look at the class documentation of the
LoggerHierarchy
for an example that uses this support.
var logger:SimpleHierarchicalLogger = new SimpleHierarchicalLogger("myLogger");
logger.setLevel(SimpleHierarchicalLogger.ALL);
logger.addHandler(new TraceHandler());
if (logger.isInfoEnabled()) {
logger.info("This is an information message.");
}
new SimpleHierarchicalLogger()
public function getParent(Void):HierarchicalLogger
Returns the parent of this logger.
This logger uses the parent to get the log level, if no one has been set to this logger manually and to get the handlers of its parents to log messages.
the parent of this logger
public function setParent(parent:HierarchicalLogger):Void
Sets the parent of this logger.
The parent is used to obtain needed configuration like handlers and levels.
parent | the parent of this logger |
setParent() in org.as2lib.env.log.ConfigurableHierarchicalLogger
public function getName(Void):String
Returns the name of this logger.
The name is a fully qualified name and the different parts are separated by
periods. The name could for example be "org.as2lib.core.BasicClass"
.
the name of this logger
public function setName(name:String):Void
Sets the name of this logger.
The name must exist of the path as well as the actual identifier. That means it must be fully qualified.
The LoggerHierarchy prescribes that the different parts of the name must be separated by periods.
name | the name of this logger |
setName() in org.as2lib.env.log.ConfigurableHierarchicalLogger
public function setLevel(level:LogLevel):Void
Sets the log level.
The level
determines which messages to log and which not.
The level
is allowed to be set to null
or undefined
.
If you do so the getLevel method returns the level of the parent.
level | the new level to control the logging of messages |
public function getLevel(Void):LogLevel
Returns the log level of this logger.
If the level has not been set, that means is undefined
, the level of
the parent will be returned.
null
or undefined
will only be returned if this level is not
defined and the parent's getLevel
method returns null
or
undefined
.
the log level of this logger
public function addHandler(handler:LogHandler):Void
Adds the new handler
.
Log handlers are used to actually log the messages. They determine what information to log and to which output device.
This method simply does nothing if the passed-in handler is null
or
undefined
.
handler | the new log handler to log messages |
public function removeHandler(handler:LogHandler):Void
Removes all occerrences of the passed-in handler
.
If the passed-in handler
is null
or undefined
the
method invocation is simply ignored.
handler | the log handler to remove |
public function removeAllHandlers(Void):Void
Removes all added log handlers.
removeAllHandlers() in org.as2lib.env.log.ConfigurableLogger
public function getAllHandlers(Void):Array
Returns all handlers this logger broadcasts to when logging a message.
These handlers are the once directly added to this logger and the once of its parents.
The handlers of the parents are obtained via the parents
getAllHandlers
method which is supposed to also return the handlers of
its parent and so on.
This method never returns null
but an empty array if there are no
handlers added to this logger nor to its parents.
Note that this method stores the parents handlers itself if it once obtained them. That is when you first log a message. It then always works with the stored handlers. That means that handlers added to its parents after the handlers have once been stored are not recognized.
all added log handlers and the ones of the parents
public function isEnabled(level:LogLevel):Boolean
Checks whether this logger is enabled for the passed-in level
.
false
will be returned if:
level
. level
is null
or undefined
.Using this method as shown in the class documentation may improve performance depending on how long the log message construction takes.
level | the level to make the check upon |
true
if this logger is enabled for the given level else
false
public function isDebugEnabled(Void):Boolean
Checks if this logger is enabled for debug level log messages.
Using this method as shown in the class documentation may improve performance depending on how long the log message construction takes.
true
if debug messages are logged
public function isInfoEnabled(Void):Boolean
Checks if this logger is enabled for info level log messages.
Using this method as shown in the class documentation may improve performance depending on how long the log message construction takes.
true
if info messages are logged
public function isWarningEnabled(Void):Boolean
Checks if this logger is enabled for warning level log messages.
Using this method as shown in the class documentation may improve performance depending on how long the log message construction takes.
true
if warning messages are logged
public function isErrorEnabled(Void):Boolean
Checks if this logger is enabled for error level log messages.
Using this method as shown in the class documentation may improve performance depending on how long the log message construction takes.
true
if error messages are logged
public function isFatalEnabled(Void):Boolean
Checks if this logger is enabled for fatal level log messages.
Using this method as shown in the class documentation may improve performance depending on how long the log message construction takes.
true
if fatal messages are logged
public function log(message, level:LogLevel):Void
Logs the passed-in message
at the given level
.
The message
is only logged when this logger is enabled for the
passed-in level
.
The message
is broadcasted to all log handlers of this logger and to
the ones of its parents or more specifically to the ones returned by the
parent's getAllHandlers
method, that normally also returns the handlers
of its parents and so on.
Note that the handlers of the parents are resloved only once, when the first message is logged. They are stored in this logger to reference them faster.
message | the message object to log |
level | the specific level at which the message shall be logged
|
public function debug(message):Void
Logs the passed-in message
at debug level.
The message
is only logged when the level is set to DEBUG
or
a level above.
The message
is broadcasted to all log handlers of this logger and to
the ones of its parents or more specifically to the ones returned by the
parent's getAllHandlers
method, that normally also returns the handlers
of its parents and so on.
Note that the handlers of the parents are resloved only once, when the first message is logged. They are stored in this logger to reference them faster.
message | the message object to log |
public function info(message):Void
Logs the passed-in message
at info level.
The message
is only logged when the level is set to INFO
or
a level above.
The message
is broadcasted to all log handlers of this logger and to
the ones of its parents or more specifically to the ones returned by the
parent's getAllHandlers
method, that normally also returns the handlers
of its parents and so on.
Note that the handlers of the parents are resloved only once, when the first message is logged. They are stored in this logger to reference them faster.
message | the message object to log |
public function warning(message):Void
Logs the passed-in message
at warning level.
The message
is only logged when the level is set to WARNING
or a level above.
The message
is broadcasted to all log handlers of this logger and to
the ones of its parents or more specifically to the ones returned by the
parent's getAllHandlers
method, that normally also returns the handlers
of its parents and so on.
Note that the handlers of the parents are resloved only once, when the first message is logged. They are stored in this logger to reference them faster.
message | the message object to log |
public function error(message):Void
Logs the passed-in message
at error level.
The message
is only logged when the level is set to ERROR
or
a level above.
The message
is broadcasted to all log handlers of this logger and to
the ones of its parents or more specifically to the ones returned by the
parent's getAllHandlers
method, that normally also returns the handlers
of its parents and so on.
Note that the handlers of the parents are resloved only once, when the first message is logged. They are stored in this logger to reference them faster.
message | the message object to log |
public function fatal(message):Void
Logs the passed-in message
at fatal level.
The message
is only logged when the level is set to FATAL
or
a level above.
The message
is broadcasted to all log handlers of this logger and to
the ones of its parents or more specifically to the ones returned by the
parent's getAllHandlers
method, that normally also returns the handlers
of its parents and so on.
Note that the handlers of the parents are resloved only once, when the first message is logged. They are stored in this logger to reference them faster.
message | the message object to log |