Class org.as2lib.env.log.logger.SimpleLogger

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

Implemented Interfaces

ConfigurableLogger

Description

SimpleLogger is a simple implementation of the ConfigurableLogger interface.

The basic methods to write the 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. That 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.

To do not waste unnecessary performance in constructing log messages that are not logged you can use the methods isEnabled, isDebugEnabled, isInfoEnabled, isWarningEnabled, isErrorEnabled and isFatalEnabled.

Note that the message does in neither case have to be a string. That means you can pass-in messages and let the actual log handler decide how to produce a string representation of the message. This 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 actaul log output 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.

Example: var logger:SimpleLogger = new SimpleLogger("mySimpleLogger"); // adds a trace handler that is responsible for making the output logger.addHandler(new TraceHandler()); // checks if the output gets actually made if (logger.isInfoEnabled()) { // log the message at the info level logger.info("This is an informative log message."); }

This logger cannot be used with the LoggerHierarchy because it does not offer hierarchy support. If you want to use your logger in a hierarchy use the SimpleHierarchicalLogger instead.

Field Index

Inherited from AbstractLogger

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

Method Index

new SimpleLogger()

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

Inherited from BasicClass

toString()

Constructor Detail

SimpleLogger

public function SimpleLogger(name:String)

Constructs a new SimpleLogger instance.

The default log level is ALL. This means all messages regardless of their level are logged.

The logger name is by default shown in the log message to identify where the message came from.

Parameters

name(optional) the name of this logger

Method Detail

getName

public function getName(Void):String

Returns the name of this logger.

This method returns null if no name has been set via the setName method nor on construction.

Return

the name of this logger

setName

public function setName(name:String):Void

Sets the name of this logger.

The name is by default shown in the log message.

Parameters

namethe new name of this logger

setLevel

public function setLevel(level:LogLevel):Void

Sets the log level.

The log level determines which messages are logged and which are not.

A level of value null or undefined is interpreted as level ALL which is also the default level.

Parameters

levelthe new log level

Specified By

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

getLevel

public function getLevel(Void):LogLevel

Returns the set level.

Return

the set level

Specified By

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

addHandler

public function addHandler(handler:LogHandler):Void

Adds a new log 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 log 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 that were added to this logger.

If there are no added handlers an empty array is returned.

Return

all added log handlers

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 message at the given level.

The message is only logged when this logger is enabled for the passed-in level.

Parameters

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

debug

public function debug(message):Void

Logs the message object at debug level.

The message is only logged when the level is set to DEBUG or a level above.

Parameters

messagethe message object to log

info

public function info(message):Void

Logs the message object at info level.

The message gets only logged when the level is set to INFO or a level above.

Parameters

messagethe message object to log

warning

public function warning(message):Void

Logs the message object at warning level.

The message gets only logged when the level is set to WARNING or a level above.

Parameters

messagethe message object to log

error

public function error(message):Void

Logs the message object at error level.

The message gets only logged when the level is set to ERROR or a level above.

Parameters

messagethe message object to log

fatal

public function fatal(message):Void

Logs the message object at fatal level.

The message gets only logged when the level is set to FATAL or a level above.

Parameters

messagethe message object to log