Version 5, last updated by Kirill Mourzenko at September 16, 2008 20:29 UTC

Probably the most basic necessity while writing code is the ability to see what it's doing. The Handy ActionScript Toolset provides a helpful logging utility implemented by com.kirillam.handy.log.HATLogger and several logging methods as part of com.kirillam.handy.core.HATObject that work with it.

All HATObjects come with these methods:

// status message
traceI( ... )

// debugging message
traceD( ... )

// warning
traceW(... )

// error message
traceE( ... )

// system failure message
traceS( ... )

They allow you to trace messages with different severity levels. The take a variable number of arguments and catenate them with spaces as separators. HATObject also provides their static equivalents straceI, straceD, straceW, straceE, straceS which should be called in static functions. I figured I'd keep the name trace in these since everybody is used to that.


If you take a look at HATLogger it has several methods that provide filtering log messages. You can filter messages by the severity level by calling setLogLevels with the levels you'd like to see logged. This is useful for turning off all logging in production builds without having to remove trace messages from the code. And if you get a bug report later on you can turn logging on again and see the output without having to put trace messages back in. You can also filter by classes by calling setLogClasses with a full or partial class path. Very useful if you're debugging a particular package and don't want to see tons of traces from other classes. By default, unless you call these methods, no filters are set and everything gets logged.

HATLogger also allows you to change the output destination of your log messages. By default they'll be printed to the trace window, but maybe you want to send them to a server. You have to implement your own class that implements the com.kirillam.handy.log.LogWriter interface and call the setWriter method with it. You can also use this to change the format of the messages being printed. Take a look at com.kirillam.handy.log.TraceWriter for an example. example.