Flash trace with Date and Time
When i am work with a Difficult Flex application its hard to find which log is come first and which one come second in the flashlog trace. I searching for any log4j api like in flex. Yes i got.. Flex have that inbuit. Here i share that how to i use in my project... The Class is "**TraceTarget**"... Using that class you can trace your log in different way like Debug, Info, Warn and Error.. Here is My example
sharedaaExample.mxml
<?xml version="1.0" encoding="UTF-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:sharedaa="com.sharedaa.\*" creationComplete="creationComplete()" preinitialize="initLogging()">
<mx:Script>
<![CDATA[
import mx.logging.Log;
import mx.logging.ILogger;
import mx.logging.LogEventLevel;
import mx.logging.targets.TraceTarget;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.events.ContextMenuEvent;
import flash.display.StageDisplayState;
private var chatContextMenu: ContextMenu;
private function initLogging(): void {
// Create a target.
var logTarget: TraceTarget = new TraceTarget();
// Log only messages for the following packages
logTarget.filters = ["com.sharedaa.\*"];
// Log all log levels.
logTarget.level = LogEventLevel.ALL;
// Add date, time, category, and log level to the output.
logTarget.includeDate = true;
logTarget.includeTime = true;
logTarget.includeCategory = true;
logTarget.includeLevel = true;
// Begin logging.
Log.addTarget(logTarget);
}
private function addContextMenu(): void {
chatContextMenu = new ContextMenu();
chatContextMenu.hideBuiltInItems();
var item: ContextMenuItem = new ContextMenuItem("www.arulraj.net");
item.addEventListener("menuItemSelect", openNewWindow);
chatContextMenu.customItems.push(item);
this.contextMenu = chatContextMenu;
}
private function openNewWindow(event: ContextMenuEvent): void {
navigateToURL(new URLRequest("http://www.arulraj.net"), "\_blank");
}
private function creationComplete(): void {
addContextMenu();
main.initMain();
main.printLog();
}
]]>
</mx:Script>
<mx:Canvas id="sharedaa">
<mx:Canvas id="mainCanvas" x="0" y="0">
<sharedaa:Main x="0" y="0" id="main" />
<mx:Label text="Example for Trace with Time" />
</mx:Canvas>
</mx:Canvas>
</mx:Application>
And the Actionscript file is
Main.as
package com.sharedaa {
import mx.containers.VBox;
import mx.logging.Log;
import mx.logging.ILogger;
public class Main extends VBox {
private static var LOG: ILogger = Log.getLogger('com.sharedaa.Main');
public function initMain(): void {
LOG.debug("intialize main");
}
public function printLog(): void {
LOG.info("This is a info log");
LOG.debug("here is a debug log");
LOG.warn("display your warnings here");
LOG.error("This is a error");
}
}
}
If you know better than this reply your ideas in comments...