O'Reilly logo

Programming Flex 2 by Joey Lott, Chafic Kazoun

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Logging Framework

The trace( ) statement can be a powerful method of logging, but if you have any formal logging experience, you likely used some sort of logging framework or built your own. Flex includes a logging framework that offers several benefits over using the trace( ) statement alone.

The logging framework consists of two main components: the logger and the target. The logger is used by an application to configure the logging framework and to send messages which are output via a target.

A target is used to specify where log messages are output. They can be output to any mechanism that Flash Player supports. The logging framework includes a TraceTarget, which inherits from LineFormattedTarget and AbstractTarget and implements the ILoggingTarget interface.

TraceTarget internally sends messages via the global trace( ) function. This will often be the target you use. Here's an example using the logging framework with TraceTarget:

<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="initializeHandler( )"> <mx:Script> <![CDATA[ import mx.logging.Log; import mx.logging.targets.TraceTarget; private var _target:TraceTarget; private function initializeHandler( ):void { _target = new TraceTarget( ); _target.includeTime = true; _target.includeLevel = true; _target.includeCategory = true; Log.addTarget(_target); } private function sendToLog( ):void { Log.getLogger("com.oreilly.programmingflex.MainClass").info("Log Message"); } ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required