Friday, January 30, 2009

Logging

xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
initialize="init()">

import mx.logging.LogEventLevel;
import mx.logging.targets.TraceTarget;
import mx.logging.ILogger;
import mx.logging.Log;
import mx.logging.LogLogger;

/*
* This is a sample application that uses a simple logger. There are 4 simple
* steps to using it:
* 1. Get an Instance of ILogger, with the appropriate category
* (Done in each class)
*
* 2. Define a Target and set it's properties
* (Done only once when initializing the logging API)
*
* 3. Add the target to Logging runtime
* (Done only once when initializing the logging API)
*
* 4. Use the instance of ILogger to log messages
*/

// 1. Get an Instance of ILogger, with the appropriate category
private var _log:ILogger = Log.getLogger("mx.com.yahoo.com");

// Initialize the remote logger
// import to do this on the application's initialize callback if you want to log
// the construction of your application's child component's
private function init():void {
// 2. Define a Target and set it's properties
var target:TraceTarget = new TraceTarget();
target.includeCategory=true;
target.includeDate=true;
target.includeLevel=true;
target.includeTime=true;
target.level=LogEventLevel.INFO;

// 3. Add the target to Logging runtime
Log.addTarget(target);
trace("Hello World");

}
//4. Use the instance of ILogger to log messages
private function sendDebugMessage():void {
_log.debug("This is a test debug level log message");
}

private function sendInfoMessage():void {
_log.info("This is a test info level log message");
}

private function sendWarnMessage():void {
_log.warn("This is a test warn level log message");
}

private function sendErrorMessage():void {
_log.error("This is a test error level log message");
}
]]>


]]>

No comments:

Post a Comment