Created
August 16, 2012 09:35
-
-
Save rjattrill/3368829 to your computer and use it in GitHub Desktop.
LogUtil for ActionScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also make sure that: