May 14 2009
AIR Logging Framework
Important: I left the project die months ago and I’m not going to update it nor supply any kind of support, so don’t write me about it. Thanks.
Get the library
The library is available here: doc_logging_framework.swc
Download the AIR application example
I also realized a dummy AIR application which can be used to test the library, you can download it here: LogAppSample
API Documentation
I documented the swc classes by using asdoc tool, the documentation is available here
About
AIR Logging Framework is a Flex library I wrote to extend the default logging framework, in order to write log messages to files on the disk and provide a custom Flex’s UI component (which can be easy used into every AIR application) to read/filtering these log files.
These are the features it offers:
- Write unlimited log message to file (LogWriter)
- Read log messages from file… even big file beyond 20Mb! (LogReader)
- Automated backup creation of log files after a specific number of Kilobytes (BackupManager)
- Automated display and filtering (by date, message type, class type) of logged messages thanks to a simple UI component which extends Flex’s Window class (LogWindow).
- Provide access to internal events (you can add event handlers to several framework’s events)
To use the library, all you need to do is to add the swc under your Flex’s library path (into the AIR project you are working on).
Then you use Flex’s logging framework as you usually do and instead of choose a log target provided by “mx.logging.targets” package, you can use LogFileTarget under “com.daveoncode.logging” package.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | // get LogFileTarget's instance (LogFileTarget is a singleton) var target:LogFileTarget = LogFileTarget.getInstance(); // The log file will be placed under applicationStorageDirectory folder target.file = File.applicationStorageDirectory.resolvePath("myApp.log"); // optional (default to "MM/DD/YY") target.dateFormat = "DD/MM/YY"; // optional (default to 1024) target.sizeLimit = 2048; // Trace all (default Flex's framework features) target.filters = ["*"]; target.level = LogEventLevel.ALL; // Begin logging (default Flex's framework features) Log.addTarget(target); |
Optionally you can add event listeners to the BackupManager:
1 2 3 4 5 | // BackupManager is a singleton class (like LogFileTarget) var manager:BackupManager = BackupManager.getInstance(); manager.addEventListener(BackupManagerEvent.BACKUP_CREATION_SUCCESS, this.backupHandler); manager.addEventListener(BackupManagerEvent.BACKUP_CREATION_FAILURE, this.failureHandler); |
And/or define your own LogWriter for LogFileTarget (it’s automatically created if you don’t specify one), in order to add event listeners to it:
1 2 3 4 5 6 | var writer:LogWriter = new LogWriter(target.file, target.sizeLimit); writer.addEventListener(LogWriterEvent.WRITE_SUCCESS, this.successHandler); writer.addEventListener(LogWriterEvent.WRITE_FAILURE, this.failureHandler); target.logWriter = writer; |
Then, to easily see logs from your AIR application, you have to create a NativeMenuItem, a Button or what you prefer that will create and display a LogWindow (from “com.daveoncode.logging.ui” package):
1 2 3 4 5 | var window:LogWindow = new LogWindow(); window.title = "Application logs"; window.width = 800; window.height = 600; window.open(true); |
The window will looks like this:



May 24th, 2009 10:47 pm
Hi,
Can you please make the source code available for us. When I am trying to sample an example I am getting ‘abc bytecode decoding ‘error. What is this? I don’t know.
May 25th, 2009 12:27 am
Which line of code is throwing the error? Could you show me the code you have written?
July 7th, 2009 7:06 am
How would you import this to an Air app using Javascript?
July 7th, 2009 12:26 pm
You can’t, this is a library for Flex, not Javascript :P
October 2nd, 2009 7:44 am
Davide:
Did you package it as a swc or swf? I didn’t find a swc in the doc_logging_framework-1.0.zip file, which makes it impossible for to use it in my AIR application project.
Thanks,
Terry
October 2nd, 2009 7:54 am
The zip file contains only one file: “doc_logging_framework-1.0.swc”… I don’t understand your issue :P
October 20th, 2009 7:05 pm
@Terry
Hi Davide,
did you manage to get the .swc file. I can see a lot of files inside the zip file but no .swc.
Thanks,
Lars
October 21st, 2009 12:29 am
You should download the swc from here: http://www.daveoncode.com/_dave_stuff/doc_logging_framework-1.0.zip (at the top of the page I wrote “get the library – The library is available here: doc_logging_framework.swc”)… if you see a lot of files, maybe you have downloaded the example AIR application (not the library) and you don’t have AIR installed on your machine (so LogAppSample.air appears as a folder rather than an executable file), you can get AIR here: http://get.adobe.com/air/ …I hope I was clear :)
November 13th, 2009 7:32 am
Hello,
1) when i try to use LogWindow as in your example, i got following error on opening.
RangeError: Error #1125: The index 1 is out of range 1.
at com.daveoncode.logging.io::DataLoader/textToObject()[C:\Documents and Settings\dzanotti\My Documents\Flex Builder 3\doc_logging_framework\src\com\daveoncode\logging\io\DataLoader.as:61]
at com.daveoncode.logging.io::DataLoader/timerHandler()[C:\Documents and Settings\dzanotti\My Documents\Flex Builder 3\doc_logging_framework\src\com\daveoncode\logging\io\DataLoader.as:95]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.utils::Timer/tick()
I guess it is because it doesn’t know where log info are ?
From your API doc, you wrote :
var lw:LogWindow = new LogWindow();
lw.logFile = File.applicationStorageDirectory.resolvePath(“myApp.log”);
but this method doesn’t seeem to exist.
Did you publish your sample application code so i get a working example ?
2) How can I log my own message
i tried something like : target.logEvent(new LogEvent(“hello world “, LogEventLevel.FATAL));
but it doesn’t seem the right way
thanks
Michel
November 13th, 2009 9:42 am
@Michel: the method exists, read here:
http://livedocs.adobe.com/flex/3/langref/flash/filesystem/File.html
To log your message, read how the default Flex logging framework works (see
mx.logging package), then use a LogFileTarget (provided by my extension).
Unfortunately, I’m loosing my Flex skills, because I’m not using it anymore and I
can’t help be so helpful :(
November 15th, 2009 2:43 pm
Hi,
1) i don’t talk about File API but about your LogWindow API.
lw.logFile is referenced in your API help, but it doesn’t appear when using your object and self completion (“lw.” doesn’t show this method).
So how do you tell the logwindow where to read log file ?
2) I found it , thanks
it was:
var mylog:ILogger = Log.getLogger(“com.a7.ged.GED”);
if (Log.isDebug())
mylog.debug(“coucou”);
Michel
February 24th, 2010 1:57 am
have the same problem like Michel…
RangeError: Error #1125: The index 1 is out of range 1.
at com.daveoncode.logging.io::DataLoader/textToObject()[C:\Documents and Settings\dzanotti\My Documents\Flex Builder 3\doc_logging_framework\src\com\daveoncode\logging\io\DataLoader.as:61]
at com.daveoncode.logging.io::DataLoader/timerHandler()[C:\Documents and Settings\dzanotti\My Documents\Flex Builder 3\doc_logging_framework\src\com\daveoncode\logging\io\DataLoader.as:95]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.utils::Timer/tick()
could you publish your code of the swc/ code of the LogAppSample? would be really nice…I want to use your logging framework.
Cheers,
Iggy
June 14th, 2010 1:44 am
Dave,
What is the license you are using for air-logging-framework?
Thanks,
Shubhra
June 21st, 2010 1:27 am
Hi,
I’m currently using you framework to log to files, however I cannot seem the get the BackupManager to work. That is, I’m setting a file size limit of 100, using the method
target.sizeLimit = 100;
But the client file happily exceeds 100kb… am I missing something?
June 22nd, 2010 3:48 am
Oh yeah, I also tried directly calling the ‘backup()’ method on the BackupManager instance: BackupManager.getInstance().backup(); but Flex could not find the backup method :(
Other than that great library!
October 27th, 2010 8:18 am
Since Davide will not reply to my enquire, does anyone know how can I rotate my files if the filesize gets bigger than the size limit?
Thank you
October 27th, 2010 12:14 pm
I think you have not set up the proper MIME type for SWC extension. My Safari would treat it as a .zip file and decompress after downloaded.
I had the same problem with .AIR files, but fixed it after updating MIME types on my webserver ;)
Just my $.02
September 12th, 2011 4:36 am
Hi Davide!
Just a question. When I specify the file size to 2048, what does it mean : bytes, kilo, mega … bytes ?
Thanks!
September 13th, 2011 2:24 am
kylobytes!