Class org.as2lib.env.log.logger.SimpleHierarchicalLogger

org.as2lib.core.BasicClass
   +--org.as2lib.env.log.logger.AbstractLogger
      +--org.as2lib.env.log.logger.SimpleHierarchicalLogger

Implemented Interfaces

ConfigurableLogger ConfigurableHierarchicalLogger

Description

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."); }

Field Index

Inherited from AbstractLogger

ALL, DEBUG, ERROR, FATAL, INFO, NONE, WARNING

Method Index

new SimpleHierarchicalLogger()

addHandler(), debug(), error(), fatal(), getAllHandlers(), getLevel(), getName(), getParent(), info(), isDebugEnabled(), isEnabled(), isErrorEnabled(), isFatalEnabled(), isInfoEnabled(), isWarningEnabled(), log(), removeAllHandlers(), removeHandler(), setLevel(), setName(), setParent(), warning()

Inherited from BasicClass

toString()

Constructor Detail

SimpleHierarchicalLogger

public function SimpleHierarchicalLogger(name:String)

Constructs a new SimpleHierarchicalLogger instance.

Parameters

namethe name of this new logger

Method Detail

getParent

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.

Return

the parent of this logger

setParent

public function setParent(parent:HierarchicalLogger):Void

Sets the parent of this logger.

The parent is used to obtain needed configuration like handlers and levels.

Parameters

parentthe parent of this logger

Specified By

setParent() in org.as2lib.env.log.ConfigurableHierarchicalLogger

getName

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".

Return

the name of this logger

setName

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.

Parameters

namethe name of this logger

Specified By

setName() in org.as2lib.env.log.ConfigurableHierarchicalLogger

setLevel

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.

Parameters

levelthe new level to control the logging of messages

Specified By

setLevel() in org.as2lib.env.log.ConfigurableLogger

getLevel

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.

Return

the log level of this logger

Specified By

getLevel() in org.as2lib.env.log.ConfigurableLogger

addHandler

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.

Parameters

handlerthe new log handler to log messages

Specified By

addHandler() in org.as2lib.env.log.ConfigurableLogger

removeHandler

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.

Parameters

handlerthe log handler to remove

Specified By

removeHandler() in org.as2lib.env.log.ConfigurableLogger

removeAllHandlers

public function removeAllHandlers(Void):Void

Removes all added log handlers.

Specified By

removeAllHandlers() in org.as2lib.env.log.ConfigurableLogger

getAllHandlers

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.

Return

all added log handlers and the ones of the parents

Specified By

getAllHandlers() in org.as2lib.env.log.ConfigurableLogger

isEnabled

public function isEnabled(level:LogLevel):Boolean

Checks whether this logger is enabled for the passed-in level. false will be returned if:

  • This logger is not enabled for the passed-in level.
  • The passed-in 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.

Parameters

levelthe level to make the check upon

Return

true if this logger is enabled for the given level else false

isDebugEnabled

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.

Return

true if debug messages are logged

isInfoEnabled

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.

Return

true if info messages are logged

isWarningEnabled

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.

Return

true if warning messages are logged

isErrorEnabled

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.

Return

true if error messages are logged

isFatalEnabled

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.

Return

true if fatal messages are logged

log

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.

Parameters

messagethe message object to log
levelthe specific level at which the message shall be logged

debug

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.

Parameters

messagethe message object to log

info

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.

Parameters

messagethe message object to log

warning

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.

Parameters

messagethe message object to log

error

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.

Parameters

messagethe message object to log

fatal

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.

Parameters

messagethe message object to log