Reply to comment

"Omit trace" analog for flex.

This one was a surprise for me. It’s easy to remove all traces from code in Flash IDE. I used to believe that the flex release export (Project=>Export release build) remove both debug and traces. But it does not. Now it’s also obvious that FlashDevelop release configuration also do not remove traces from sources. Of course common user doesn’t even have any applications displaying traces, but this is still affect performance. And of course this is bad-looking.

I googled a little for a solution. No, to all appearances there is no “omit trace actions” like option in flex sdk compiler, so there are no many ways out.

The easiest way is to do search and replace for all project. Replace “trace” with “//trace”, that’s all.

Also flex has pretty strong logging framework mx.logging. Here is a little example:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init();">
  3. <mx:Script>
  4. <![CDATA[
  5. import mx.logging.Log;
  6. import mx.logging.ILogger;
  7. import mx.logging.LogEventLevel;
  8. import mx.logging.targets.TraceTarget;
  9.  
  10. private var _log:ILogger;
  11. private var _traceTarget:TraceTarget;
  12.  
  13. private function init():void {
  14. _traceTarget = new TraceTarget();
  15. _traceTarget.filters=["*"];
  16. _traceTarget.level = LogEventLevel.ALL;
  17. _traceTarget.includeDate = false;
  18. _traceTarget.includeTime = false;
  19. _traceTarget.includeCategory = true;
  20. _traceTarget.includeLevel = true;
  21. Log.addTarget(_traceTarget);
  22.  
  23. _log = Log.getLogger("ExampleLogger");
  24. _log.info("Your tracing like a pro!");
  25. }
  26. ]]>
  27. </mx:Script>
  28. </mx:Application>
You can setup log appearance, set keys for log messages and then filter logs by keys. In whole it's pretty complex and bulky as trace substitute.
Also you can use compile time conditionals. In sources you have to write like this:
  1. CONFIG::debugging {
  2. trace(counter);
  3. }
And then add -define=CONFIG::debugging,false or -define=CONFIG::debugging,true option to mxmlc compiler depending on do we need traces or not. For the Flex Builder 3 it can be added in Project=>Properties=>Flex compiler=>Additional compiler arguments. Still I haven’t found where separate options for debug build and release build can be added. It’s more convenient for FlashDevelop. Open Project=>Properties=>Build tab and add options to pre-build command line and post-build command line.

Reply

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.