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:19:40 |
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.
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.
Summary
Class properties
- LEVEL_DEBUG : String
- LEVEL_INFO : String
- LEVEL_WARN : String
- LEVEL_ERROR : String
- LEVEL_FATAL : String
- LEVEL_STATUS : String
- theInstance : Log
Class methods
- getInstance : Log
- debug (inText:String, inSender:String) : Void
- Log a message with debug level
- info (inText:String, inSender:String) : Void
- Log a message with info level
- error (inText:String, inSender:String) : Void
- Log a message with error level
- warn (inText:String, inSender:String) : Void
- Log a message with warning level
- fatal (inText:String, inSender:String) : Void
- Log a message with fatal level
- status (inText:String, inSender:String) : Void
- Log a message with status level
- addLogListener (inFunction:Function) : Void
- Add a function as listener to LogEvent events
- showTrace (inShow:Boolean) : Void
- Set whether log messages should be output as a trace
Instance methods
- send (inText:String, inSender:String, inLevel:String) : Void
- Dispatch a LogEvent with the input parameters; trace if flag is set to do so
- addListener (inFunction:Function) : Void
- Add a function to the event listeners
- doShowTrace (inShow:Boolean) : Void
- Set whether log messages should be output as a trace
Class properties
LEVEL_DEBUG
static LEVEL_DEBUG:String = "debug"
(read)
LEVEL_ERROR
static LEVEL_ERROR:String = "error"
(read)
LEVEL_FATAL
static LEVEL_FATAL:String = "fatal"
(read)
LEVEL_INFO
static LEVEL_INFO:String = "info"
(read)
LEVEL_STATUS
static LEVEL_STATUS:String = "status"
(read)
LEVEL_WARN
static LEVEL_WARN:String = "warn"
(read)
theInstance
Instance properties
mDoTrace
private mDoTrace:Boolean = true
(read)
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
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
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
typical toString() of the calling class
Usage:
-
Log.fatal("This is a fatal message", toString());
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
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.
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
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
typical toString() of the calling class
Usage:
-
Log.warn("This is a warning message", toString());
Instance methods
addListener
private function addListener (
inFunction:Function) : Void
Add a function to the event listeners
doShowTrace
private function doShowTrace (
inShow:Boolean) : Void
Set whether log messages should be output as a trace
Parameters:
inShow:
if true, log messages are output as a trace
send
private function send (
inText:String,
inSender:String,
inLevel:String) : Void
Dispatch a LogEvent with the input parameters; trace if flag is set to do so
Parameters:
inText :
the message
inSender:
a String denoting the source of the message
inLevel :
the level of the message