Part of the newest corelib 0.92.1, an Adobe AIR only class that provides a log target for the Flex logging framework, that logs files to a file on the user’s system.I think it’s useful when you want to write the logs into a specified file instead of the default one.
Methods
FileTarget()
- public function FileTarget(logFile:File = null)
- Parameters
- logFile:File (default = null)
clear()
- public function clear():void
- clear the log messages in the log file.
Properties
- logURI:String[read-only]
- public function get logURI():String
Return
- return the URI of the log file.
Screenshot:
The following is full source code of FileTargetDemo.as:
Download: FileTargetDemo.as
- package
- {
- import com.adobe.air.logging.FileTarget;
- import flash.events.Event;
- import flash.filesystem.File;
- import mx.collections.ArrayCollection;
- import mx.core.WindowedApplication;
- import mx.logging.Log;
- import mx.logging.LogEventLevel;
- public class FileTargetDemo extends WindowedApplication
- {
- public function FileTargetDemo()
- {
- super();
- }
- [Bindable]
- protected var myData:ArrayCollection;
- [Bindable]
- protected var fileTarget:FileTarget;
- protected var logFilePath:String;
- [Bindable]
- protected var logContent:String;
- protected function initLogging():void
- {
- logFilePath = File.applicationDirectory.nativePath + "\\"+ new Date().toLocaleDateString()+".txt";
- var file:File = new File(logFilePath);
- fileTarget = new FileTarget(file);
- fileTarget.filters=["mx.rpc.*","mx.messaging.*"];
- fileTarget.level = LogEventLevel.ALL;
- fileTarget.includeDate = true;
- fileTarget.includeTime = true;
- fileTarget.includeCategory = true;
- fileTarget.includeLevel = true;
- Log.addTarget(fileTarget);
- }
- protected function showLog():void
- {
- var file:File = new File(logFilePath);
- if( file.exists);
- {
- file.load();
- file.addEventListener(Event.COMPLETE,fileLoadCompleteHandler);
- }
- }
- private function fileLoadCompleteHandler(event:Event):void
- {
- logContent = String(event.currentTarget.data);
- }
- protected function clearLog():void
- {
- fileTarget.clear();
- showLog();
- }
- protected function srv_ResultHandler(event:Event):void
- {
- myData = event.currentTarget.lastResult.data.result;
- }
- }
- }
And FileTargetDemoView.mxml
Download: FileTargetDemoView.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <FileTargetDemo
- xmlns="*"
- xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="absolute"
- creationComplete="initLogging()">
- <mx:HTTPService
- id="srv"
- url="trace_example_data.xml"
- useProxy="false"
- result=" srv_ResultHandler(event);"
- />
- <mx:Panel
- title="FileTarget Demo"
- width="100%"
- height="100%">
- <mx:VDividedBox
- width="100%"
- height="100%">
- <mx:LineChart id="chart"
- dataProvider="{myData}"
- showDataTips="true"
- width="100%"
- height="100%">
- <mx:horizontalAxis>
- <mx:CategoryAxis
- categoryField="month"/>
- </mx:horizontalAxis>
- <mx:series>
- <mx:LineSeries
- yField="apple"
- name="Apple"/>
- <mx:LineSeries
- yField="orange"
- name="Orange"/>
- <mx:LineSeries
- yField="banana"
- name="Banana"/>
- </mx:series>
- </mx:LineChart>
- <mx:TextArea
- editable="false"
- text="{logContent}"
- width="100%"
- height="100%"/>
- </mx:VDividedBox>
- <mx:ControlBar>
- <mx:Button id="b1"
- label="Load Data"
- click="srv.send();"
- />
- <mx:Button
- label="show log"
- click="showLog()"/>
- <mx:Button
- label="clear log"
- click="clearLog()"/>
- <mx:Label id="logFileURI"
- text="log file uri:{fileTarget.logURI}"/>
- </mx:ControlBar>
- </mx:Panel>
- </FileTargetDemo>
Enjoy!

January 7th, 2009
Ntt.cc 








Posted in
Tags: 
RSS Feed
Email Feed