Skip to content

Instantly share code, notes, and snippets.

@rjattrill
Created August 16, 2012 09:35
Show Gist options
  • Save rjattrill/3368829 to your computer and use it in GitHub Desktop.
Save rjattrill/3368829 to your computer and use it in GitHub Desktop.
LogUtil for ActionScript
package util {
import flash.utils.getQualifiedClassName;
import mx.logging.ILogger;
import mx.logging.Log;
import mx.logging.LogEventLevel;
import mx.logging.targets.TraceTarget;
public class LogUtil {
public static function getLogger(c:Object):ILogger {
var className:String = getQualifiedClassName(c);
return mx.logging.Log.getLogger(className.replace("::", "."));
}
public static function initLogging():void {
// Create a target.
var logTarget:TraceTarget = new TraceTarget();
logTarget.filters=["com.acme.*"];
// Log all log levels.
logTarget.level = LogEventLevel.ALL;
// Add date, time, category, and log level to the output.
logTarget.includeDate = true;
logTarget.includeTime = true;
logTarget.includeCategory = true;
logTarget.includeLevel = true;
// Begin logging.
mx.logging.Log.addTarget(logTarget);
}
}
}
// To use this:
// 1. Instantiate
// private var log:ILogger = LogUtil.getLogger(this);
// 2. Log
// log.info("Hello world");
//
// Adapted from:
// http://blogs.adobe.com/tomsugden/2009/08/best_practices_for_the_flex_lo.html
@rjattrill
Copy link
Author

Also make sure that:

  • mxmlc compiler has param -debug=true
  • mm.cfg file in c:\users\ is configured for trace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment