Showing posts with label Flex Logging. Show all posts
Showing posts with label Flex Logging. Show all posts

Sunday, November 19, 2006

Tracing and logging in Flex

This is another area which is pretty simple and powerful, but still many end up writing their own version.

All you have to do is define a new logging target or use the existing 'TraceTarget' to direct logging statements to it.

var traceTarget:ILoggingTarget = new LogViewerTarget(debugBox);
traceTarget.filters = ["com.adobe.*"];
traceTarget.level = LogEventLevel.DEBUG;
Log.addTarget(traceTarget);

Then, to log use one of the methods in the logger class:

private var logger : ILogger = Log.getLogger("com.adobe.SomeClass");

The logging target class looks like, pass the textarea in constructor if you wish to view the log during development:

use namespace mx_internal;
...
public class LogViewerTarget extends LineFormattedTarget
{
....
public function LogViewerTarget() { super(); }

override mx_internal function internalLog(message:String):void
{ this.logs.text += message + "\n"; }
}