Log templates for Flex

Categories: flex
Written By: sebi

There’s a lot of different approach for logging in Flex, involving third party loggers, custom consoles, and a lot of debates.
With working and mainting huge – and sometimes undocumented – applications, I’ve found that most of the time introducing 3rd party logging engines just leads to more problem than advantage.
I show a simple way to use the built in logging, with almost zero typing.

To keep the code portable and reusable, I usually use the built-in logging framework of Flex.
With proper log targets, almost all kind of log outputs are achievable relatively easily.

One important aspect is how much overhead it adds in the term of development time to setup and use logging.
To reduce this, and avoid always typing these lines, I simply added the following code templates to Flash Builder:

The first declares the logger with the current class’s package and class name, and imports the logger classes:

${:import(mx.logging.ILogger,mx.logging.Log)}
private static const LOG:ILogger = mx.logging.Log.getLogger( "${enclosing_package_and_type}" );

The second allows you to put a log line into the method:

if( Log.${is_level:values(isDebug,isInfo,isWarn,isError)}())
{
	LOG.${level:values(debug,info,warn,error)}( "${enclosing_method}() :: ${cursor}" );
}

It will provide you a dropdown menu for both the guard condition and the actual log line itself:

Dropdown menu for selecting log levels

It allows you to quickly declare and use log lines with a few keystrokes.

Flash Builder > Preferences > Flash Builder > Editors > Code Templates > Actionscript

Flash Builder > Preferences > Flash Builder > Editors > Code Templates > Actionscript

Leave a Reply