package
{
import flash.events.StatusEvent;
import flash.net.LocalConnection;
import mx.controls.TextArea;
import mx.core.mx_internal;
import mx.logging.ILogger;
import mx.logging.LogEvent;
import mx.logging.targets.LineFormattedTarget;
use namespace mx_internal;
/**
* The professional_flex_code_26_LocalConnectionTraceTarget
extends the
* LineFormattedTarget
class to provide
* a basic output mechanism. This target uses
* LocalConnection
to output the trace
* messages to any other application using
* LocalConnection
listening on
* _flex2tracepanel
.
*
* @see mx.logging.targets.LineFormattedTarget
*/
public class professional_flex_code_26_LocalConnectionTraceTarget extends LineFormattedTarget {
/**
* Constructor.
*/
public function professional_flex_code_26_LocalConnectionTraceTarget() {
super();
lc = new LocalConnection();
lc.addEventListener(StatusEvent.STATUS, statusEventHandler);
}
/**
* @private
*/
private var lc:LocalConnection;
/**
* @private
* @internal Need to keep Flex 2 from throwing unhandled
* status errors
*/
private function statusEventHandler(event:StatusEvent):void {
; // Handles Event Status Calls
}
/**
* The internalLog
method handles the
* sending of messages.
*
* @param event LogEvent
sent to a
* ILogger
from the Log
class.
*/
override public function logEvent(event:LogEvent):void
{
var level:int = event.level;
var date:String = ""
if (includeDate || includeTime)
{
var d:Date = new Date();
if (includeDate)
{
date = Number(d.getUTCMonth() + 1).toString() + "/" +
d.getUTCDate().toString() + "/" +
d.getUTCFullYear() + fieldSeparator;
}
if (includeTime)
{
date = pad(d.getUTCHours()) + ":" +
pad(d.getUTCMinutes()) + ":" +
pad(d.getUTCSeconds()) + "." +
pad(d.getUTCMilliseconds()) + fieldSeparator;
}
}
var category:String = includeCategory ?
ILogger(event.target).category + fieldSeparator : "";
// Connection and Method specific to C# .Net applicaton Flex2TracePanel
lc.send( "_flex2tracepanel", "logMessage", date + category + event.message, level);
}
/**
* The pad method adds leading 0's to single digit numbers.
*
* @return The string representation of two digit leading 0 number.
*/
private function pad(num:Number):String
{
return num > 9 ? num.toString() : "0" + num.toString();
}
}
}