A Simple But Very Useful AIR log Class
By admin | September 13, 2008
In the article the list of helpful Flex or Flash debug tools, we could find many flex or flash debug tools. But for some applications, maybe we don’t need to input the whole package debugging. Following is a class which very simple but could meet basic debugging function requirement and could be used easily. Following is the code:
- package com.engroup.log
- ...
- /**
- * The custom logger factory of eSoftHead company
- */
- public class LoggerFactory
- {
- private static var instance:LoggerFactory = new LoggerFactory();
- function LoggerFactory()
- {
- if (instance != null) {
- throw new Error("The instance Logger already be exist");
- } // hard-code or can read the configuration file in application path var logTarget:TraceTarget = new TraceTarget();
- logTarget.filters = ["com.engroup.*"];
- logTarget.level = LogEventLevel.ALL;
- logTarget.includeCategory = true;
- logTarget.includeDate = true;
- logTarget.includeLevel = true;
- logTarget.includeTime = true;
- Log.addTarget(logTarget);
- } private function getInternalLog(classReference:Class): ILogger {
- var type:XML = describeType(classReference);
- var className:String = type.@name;
- var category:String = className.replace("::", ".");
- return Log.getLogger(category);
- }
- public static function getLogger(classReference:Class): ILogger {
- return instance.getInternalLog(classReference);
- }
- }
Following is an example:
- private static var log:ILogger = LoggerFactory.getLogger(ABC);
- log.debug("The example log message");
Chinese:here
Topics:
Adobe-Flash |
1 Comment »
|
Tags: air, class, log, logger
Trackbacks