Skip to content

Instantly share code, notes, and snippets.

@hisui
Last active December 14, 2015 15:29
Show Gist options
  • Save hisui/5108314 to your computer and use it in GitHub Desktop.
Save hisui/5108314 to your computer and use it in GitHub Desktop.
Getting ILogger instance with a name of a class in which statically doing it.
package {
import mx.logging.ILogger;
import mx.logging.Log;
public final class LogUtil {
public static function get cinit():ILogger
{
// This matching fails on AIR runtime..
const result:Object = /[^\/\s.:]+(?=\$cinit\(\))/.exec(new Error().getStackTrace());
if (!result) {
throw new Error("Call this function at time to initialize static variable..");
}
return Log.getLogger(result[0]);
}
}
}
package {
import mx.logging.ILogger;
public class Usage {
static const log:ILogger = LogUtil.cinit;
public function Usage()
{
log.debug("Hello, World!!!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment