Frage

I have an Air application. It consist of an HTML component. I create a flex application and launch this application in HTML component of Air Application. I am able to capture the trace output of Air application but I can not capture trace output of flex application. As this flex application is launched in Air application's HTML component. I use vizy that output the log prints. How can I capture the trace output of flex web application. Thanks

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top