The Logging Framework
The trace() statement can be a
powerful method of logging, but if you have been exposed to logging in the
past, 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 that 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"); } ]]> ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access