Log

Kind of class: public class
Package:
Inherits from:
  • EventDispatcher
Author: stephan.bezoen
Classpath: org.asaplibrary.util.debug.Log
File last modified: Wednesday, 11 May 2011, 18:55:44
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(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 getQualifiedClassName(this);
    }
    
    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
Class methods
  • 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
  • removeLogListener (inFunction:Function) : void
    • Remove a function as listener to LogEvent events
  • showTrace (inShow:Boolean) : void
    • Set whether log messages should be output as a trace

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(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());

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());

removeLogListener

static function removeLogListener(inFunction:Function) : void

Remove a function as listener to LogEvent events

Parameters
inFunction:the function that handles LogEvents

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());