Index: lams_common/src/flash/org/lamsfoundation/lams/common/util/Debugger.as
===================================================================
diff -u -r0ef141727f237eac4ae0dc565ad76af764f92234 -r27cd1238c7ed8444df351dd4bc7401c2f7f5a8c1
--- lams_common/src/flash/org/lamsfoundation/lams/common/util/Debugger.as (.../Debugger.as) (revision 0ef141727f237eac4ae0dc565ad76af764f92234)
+++ lams_common/src/flash/org/lamsfoundation/lams/common/util/Debugger.as (.../Debugger.as) (revision 27cd1238c7ed8444df351dd4bc7401c2f7f5a8c1)
@@ -1,4 +1,5 @@
-import org.lamsfoundation.lams.common.util.*
+import org.lamsfoundation.lams.common.util.*
+import mx.events.*
/**
* Debug
@@ -23,11 +24,34 @@
private static var _allowDebug:Boolean = true;
private static var _currentClass:String;
+ private static var _instance:Debugger = null;
+ //These are defined so that the compiler can 'see' the events that are added at runtime by EventDispatcher
+ private var dispatchEvent:Function;
+ public var addEventListener:Function;
+ public var removeEventListener:Function;
+
+ private static var _msgLog:Array;
+
+
+ //TODO DI 07/06/05 Add code to get dump of flash from _root
+
//Constructor
- function Debugger() {
-
- }
+ private function Debugger() {
+ //Set up this class to use the Flash event delegation model
+ EventDispatcher.initialize(this);
+ _msgLog = [];
+ }
+
+ /**
+ * Retrieves an instance of the Application singleton
+ */
+ public static function getInstance():Debugger{
+ if(Debugger._instance == null){
+ Debugger._instance = new Debugger();
+ }
+ return Debugger._instance;
+ }
public function set allowDebug(arg:Boolean):Void{
@@ -45,7 +69,7 @@
public function get severityLevel():Number{
return _severityLevel;
}
-
+
/**
* Method to print a message to the output - trace or window...
@@ -55,8 +79,10 @@
* @param fname (Optional) Name of the function calling this log message
* @param currentClass (Optional)Name of the class
*/
- public static function log(msg:String,level:Number,fname:String,currentClass:Object):Void{
-
+ public static function log(msg:String,level:Number,fname:String,currentClass:Object):Void{
+ //Ensure we have an instance
+ getInstance();
+
if(_allowDebug){
if(arguments.length == 1){
level = 4;
@@ -70,8 +96,15 @@
trace("-----------In:"+_currentClass+"-----------");
}
-
- trace("["+fname+"]"+msg);
+ //Write to trace
+ msg = "["+fname+"]"+msg
+ trace(msg);
+ var date:Date = new Date();
+
+ //Write to log
+ _msgLog.push({date:date,msg:msg,level:level});
+ //Dispatch update event
+ _instance.dispatchEvent({type:'update',target:_instance});
}
}
}
@@ -83,15 +116,70 @@
* @param fname (Optional) Name of the function calling this log message
*/
public static function debug(msg:String,fname:String):Void{
-
if(_allowDebug){
if(arguments.length == 1){
fname = "";
}
-
log(msg,4,fname,undefined);
-
}
- }
-
+ }
+
+ /**
+ * @param format:Object An object containing various format options for viewing the log
+ * @returns the message log formatted
+ */
+ public function getFormattedMsgLog(format:Object):String {
+ var ret:String;
+ if(!format){
+ format = {};
+ format.date = false;
+ }
+ //Loop through messages and build return string
+ for(var i=0;i<_msgLog.length;i++) {
+ ret += buildMessage(format,_msgLog[i]);
+ }
+ return ret;
+ }
+
+ /**
+ * Construct a message from the msgObject using the format object
+ *
+ * @returns String - the formatted string
+ */
+ private function buildMessage(format:Object,msgObj:Object):String {
+ var ret:String;
+ var colour:String;
+ //Get the color for the level
+ switch (msgObj.level) {
+ case CRITICAL :
+ colour='#ff0000';
+ break;
+ case GEN :
+ colour='#0000ff';
+ break;
+ case GEN :
+ colour='#00ff00';
+ break;
+ default:
+ colour='#555555';
+ }
+
+ //Build font tags
+ var fontOpenTag:String = ''
+ var fontCloseTag:String = ''
+ //Include date?
+ if(format.date) {
+ ret = fontOpenTag + msgObj.msg + ' date : ' + msgObj.date.toString() + fontCloseTag + '
';
+ } else {
+ ret = fontOpenTag + msgObj.msg + fontCloseTag + '
';
+ }
+ return ret;
+ }
+
+ /**
+ */
+ function get msgLog(){
+ return _msgLog;
+ }
+
}
\ No newline at end of file