One possible solution, use mx.logging.Log for debug traces and custom LogTarget to capture them.
It would go something like this. Declare the necessary objects:
private var logTarget:MyLogTarget= new MyLogTarget();
private var myLog:ILogger;
Set up logging where you initialize the application:
myLog=Log.getLogger("MyApp");
Log.addTarget(logTarget);
Log stuff:
myLog.info("Something something.");
myLog.warn("This is weird!");
myLog.error("This shouldn't happen!");
The meat of the solution is the custom log target, MyLogTarget.as:
package
{
import mx.logging.LogEvent;
import mx.logging.targets.LineFormattedTarget;
public class MyLogTarget extends LineFormattedTarget
{
public var log:Vector.<String>=new Vector.<String>;
public function MyLogTarget()
{
super();
}
override public function logEvent(event:LogEvent):void
{
trace(event.message);
log.push(event.message+"\n");
}
}
}
This particular implementation just stores all traces in a vector of Strings, but you can modify it to save the log to disk, send it to a service, trace it on screen or whatever works for you.