package ro.badu.utils.debug { import flash.utils.getTimer; import mx.utils.ObjectUtil; CONFIG::AIR_LOG { import ro.badu.utils.debug.logger.LogWriter; } /* A simple class which allows you to perform extensive traces with line numbers. @author : Dinu Bogdan Gabriel - badu@badu.ro Usage example: protected function someMethod():void { var myArrayCollection : ArrayCollection = new ArrayCollection(); myArrayCollection.addItem({firstname:"test1" , lastname: "test2"}); myArrayCollection.addItem({firstname:"test3" , lastname: "test4"}); Tracer.log( new Error() , myArrayCollection , true); } public static function log( source : Error , message:Object=null, isObjectUtilDump : Boolean = false ):void Parameters : source : Error - the place where the trace comes from, usually using "new Error()" will provide all the info you need, regardless of the type of class / method message - the message you want to trace. Can accept complex objects which in combination with isObjectUtilDump= true will use ObjectUtil to dump it all isObjectUtilDump - see above Important Note : 1. do not forget to set compiler param -define CONFIG::AIR_LOG false if you are using it as it is 2. I recommend you to use -define CONFIG::DEBUG true too and do conditionals on traces that are "permanent" (remains there until you deliver) */ public class Tracer { public static const brackets : RegExp = new RegExp(/\[|\]/ig); public static const linebreak : RegExp = new RegExp(/\n/ig); public static const twopoints : RegExp = new RegExp(/\:/ig); public static const doubletwopoints : RegExp = new RegExp(/\::/ig); public static function log( source : Error , message:Object=null, isObjectUtilDump : Boolean = false ):void { if (CONFIG::AIR_LOG) { var _log:LogWriter = new LogWriter(); } var _tracedMessage:String ; var _lines : Array = (source.getStackTrace().split(linebreak)[1] as String).split(brackets); var _where : String = _lines[0] as String; var _sourceFile : String = (_lines[1] as String).split(twopoints)[2] as String; _where = _where.replace(doubletwopoints , " => "); _tracedMessage = "[" + getTimer() + " ms]" + _where.replace(".." , "\t")+" [LINE #"+_sourceFile+"]"; if (isObjectUtilDump) { if( message != null ) _tracedMessage += "\n" + ObjectUtil.toString(message); } else { if( message != null ) _tracedMessage += " - " + message; } if (CONFIG::AIR_LOG) { _log.log(_tracedMessage); } trace(_tracedMessage); } } }