Last active
December 14, 2015 15:29
-
-
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.
This file contains hidden or 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 { | |
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]); | |
} | |
} | |
} |
This file contains hidden or 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 { | |
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