Flex 2 comes with a great new Logging API. I've created an AS 3.0 class that allows you to route logging messages to the Flex Trace Panel.
To use the class, create the folder structure de/richinternet/logging inside your Flex 2 project and copy the TracePanelTarget class to this location. Inside your Flex 2 application you add a new instance of the TracePanelTarget as a target to the Log class, e.g.
private function initApp():Void
var target:TracePanelTarget = new TracePanelTarget();
target.level = LogEventLevel.DEBUG;
Later, you acquire an ILogger instance from the Log class and invoke a logging method on it. The parameter passed is the category you want a logger for (by convention the category maps to the fully qualified class name in which the logger is used):
Log.getLogger("foo").info("this is an info message!");
Log.getLogger("foo").warn("this is a warn message!");
For a full discussion of the Logging API check the Flex 2 documentation.
Please note that as of now the Flex Trace Panel is not fully compatible to Flex 2 - trying to trace complex objects will fail because some techniques used in the Dumper class no longer work in Flex 2. Also, I haven't adjusted the Flex Trace Panel log levels to the Flex 2 log levels yet. I will create an updated version of the Flex Trace Panel that fully supports Flex 2 in the future - so, just take it as a preview :)
Download available here.
There are no comments for this entry.