Access keys

Log

Kind of class: class
Inherits from: Dispatcher
Author: stephan.bezoen
Classpath: org.asapframework.util.debug.Log
File last modified: Thursday, 12 October 2006, 11:11:47
This class implements a simple logging functionality that dispatches an event whenever a log message is received.

The object sent with the event is of type LogEvent. The LogEvent class contains public properties for the text of the message,
a String denoting the sender of the message,and the level of importance of the message.
By default, log messages are also output as traces to the Flash IDE output window. This behaviour can be changed.
Example:
Log.addEventListener(EventDelegate.create(this, onLogEvent));	// handle events locally
Log.showTrace(false);	// don't output log messages as traces

Log.debug("This is a debug message", toString());
Log.error("This is an error message", toString());
Log.info("This is an info message", toString());

private function onLogEvent (e:LogEvent) {
    // handle the event by showing the message as a trace
    trace(e.text);
}

public function toString () : String {
    return "TestClass";
}
This will show the following output in the Flash IDE output window:

This is a debug message
This is an error message
This is an info message

The standard trace output of the Log class looks as follows:

11 debug: This is a debug message -- TestClass
11 error: This is an error message -- TestClass
11 info: This is an info message -- TestClass

The number "11" is the time at which the log message was generated. This time is not kept in the LogEvent class.

Class properties

LEVEL_DEBUG

static LEVEL_DEBUG:String = "debug"
(read,write)

LEVEL_ERROR

static LEVEL_ERROR:String = "error"
(read,write)

LEVEL_FATAL

static LEVEL_FATAL:String = "fatal"
(read,write)

LEVEL_INFO

static LEVEL_INFO:String = "info"
(read,write)

LEVEL_STATUS

static LEVEL_STATUS:String = "status"
(read,write)

LEVEL_WARN

static LEVEL_WARN:String = "warn"
(read,write)

Class methods

addLogListener

static function addLogListener (
inFunction:Function) : Void
Add a function as listener to LogEvent events
Parameters:
inFunction:
the function to handle LogEvents
Usage:
Log.addLogListener(EventDelegate.create(this, onLog));

private function onLog (e:LogEvent) {
}

debug

static function debug (
inText:String, inSender:String) : Void
Log a message with debug level
Parameters:
inText :
the message
inSender:
a String denoting the source of the message;
typical toString() of the calling class
Usage:
Log.debug("This is a debug message", toString());

error

static function error (
inText:String, inSender:String) : Void
Log a message with error level
Parameters:
inText :
the message
inSender:
a String denoting the source of the message;
typical toString() of the calling class
Usage:
Log.error("This is an error message", toString());

fatal

static function fatal (
inText:String, inSender:String) : Void
Log a message with fatal level
Parameters:
inText :
the message
inSender:
a String denoting the source of the message;
typical toString() of the calling class
Usage:
Log.fatal("This is a fatal message", toString());

getInstance

static function getInstance (
) : Log
Returns:
singleton instance of Logger

info

static function info (
inText:String, inSender:String) : Void
Log a message with info level
Parameters:
inText :
the message
inSender:
a String denoting the source of the message;
typical toString() of the calling class
Usage:
Log.info("This is an info message", toString());

showTrace

static function showTrace (
inShow:Boolean) : Void
Set whether log messages should be output as a trace
Parameters:
inShow:
if true, log messages are output as a trace
Set this to false if a log listener also outputs as a trace.
Usage:
Log.showTrace(false);

status

static function status (
inText:String, inSender:String) : Void
Log a message with status level
Parameters:
inText :
the message
inSender:
a String denoting the source of the message;
typical toString() of the calling class
Usage:
Log.status("This is a status message", toString());

warn

static function warn (
inText:String, inSender:String) : Void
Log a message with warning level
Parameters:
inText :
the message
inSender:
a String denoting the source of the message;
typical toString() of the calling class
Usage:
Log.warn("This is a warning message", toString());