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:

logwindow