Created
October 11, 2010 20:49
-
-
Save mattupstate/621198 to your computer and use it in GitHub Desktop.
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 flash.display.DisplayObject; | |
| import flash.utils.getQualifiedClassName; | |
| import nl.demonsters.debugger.MonsterDebugger; | |
| /** | |
| * The Out class is the application's logger console proxy. All messages are sent to a running | |
| * instance of De MonsterDebugger. | |
| * @see http://www.demonsterdebugger.com/ | |
| */ | |
| public class Out | |
| { | |
| private static var _levels:Object = {}; | |
| private static var _silenced:Object = {}; | |
| private static var _packages:Object = {}; | |
| /** | |
| * INFO message console color | |
| */ | |
| public static var INFO_COLOR:uint = 0x757575; | |
| /** | |
| * STATUS message console color | |
| */ | |
| public static var STATUS_COLOR:uint = 0x0098FF; | |
| /** | |
| * DEBUG message console color | |
| */ | |
| public static var DEBUG_COLOR:uint = 0x009932; | |
| /** | |
| * WARNING message console color | |
| */ | |
| public static var WARNING_COLOR:uint = 0xFF9900; | |
| /** | |
| * ERROR message console color | |
| */ | |
| public static var ERROR_COLOR:uint = 0xCC0000; | |
| /** | |
| * FATAL message console color | |
| */ | |
| public static var FATAL_COLOR:uint = 0x000000; | |
| /** | |
| * Static constant for INFO level | |
| */ | |
| public static const INFO:int = 0; | |
| /** | |
| * Static constant for STATUS level | |
| */ | |
| public static const STATUS:int = 1; | |
| /** | |
| * Static constant for DEBUG level | |
| */ | |
| public static const DEBUG:int = 2; | |
| /** | |
| * Static constant for WARNING level | |
| */ | |
| public static const WARNING:int = 3; | |
| /** | |
| * Static constant for ERROR level | |
| */ | |
| public static const ERROR:int = 4; | |
| /** | |
| * Static constant for FATAL level | |
| */ | |
| public static const FATAL:int = 5; | |
| /** | |
| * Specifies if the proxy should send messages to the logger console or not. | |
| */ | |
| public static var enabled:Boolean = true; | |
| /** | |
| * Enables a particular logging level | |
| * @param level A logging level to enable | |
| */ | |
| public static function enableLevel( level:uint ):void | |
| { | |
| _levels["Level" + level.toString()] = true; | |
| } | |
| /** | |
| * Disables a particular logging level | |
| * @param level A logging level to disable | |
| */ | |
| public static function disableLevel( level:uint ):void | |
| { | |
| _levels["Level" + level.toString()] = false; | |
| } | |
| /** | |
| * Determines if a logging level is enabled | |
| * @param level A logging level to check | |
| * @return True or false | |
| */ | |
| public static function isLevelEnabled( level:uint ):Boolean | |
| { | |
| return _levels["Level" + level.toString()]; | |
| } | |
| /** | |
| * Enables all logging levels | |
| */ | |
| public static function enableAllLevels():void | |
| { | |
| enableLevel( INFO ); | |
| enableLevel( STATUS ); | |
| enableLevel( DEBUG ); | |
| enableLevel( WARNING ); | |
| enableLevel( ERROR ); | |
| enableLevel( FATAL ); | |
| } | |
| /** | |
| * Disables all logging levels | |
| */ | |
| public static function disableAllLevels():void | |
| { | |
| disableLevel( INFO ); | |
| disableLevel( STATUS ); | |
| disableLevel( DEBUG ); | |
| disableLevel( WARNING ); | |
| disableLevel( ERROR ); | |
| disableLevel( FATAL ); | |
| } | |
| /** | |
| * Checks if an class type is silenced. | |
| * @param o An instance of the class type you wish to check | |
| * @return True or false | |
| */ | |
| public static function isSilenced( o:* ):Boolean | |
| { | |
| var s:String = getClassName( o ); | |
| return _silenced[s]; | |
| } | |
| /** | |
| * Checks if a package is silenced. | |
| * @param packageName The package name you wish to check | |
| * @return True or false | |
| */ | |
| public static function isPackageSilenced( packageName:String ):Boolean | |
| { | |
| for each( var pack:String in _packages ) | |
| { | |
| if( packageName.indexOf( pack ) == 0 ) | |
| return true; | |
| } | |
| return false; | |
| } | |
| /** | |
| * Silences a speficied class type | |
| * @param o An instance of the class you wish to silence | |
| */ | |
| public static function silence( o:* ):void | |
| { | |
| var s:String = getClassName( o ); | |
| _silenced[s] = true; | |
| } | |
| /** | |
| * Silences a specified package | |
| * @param packageName The package name you wish to silence | |
| */ | |
| public static function silencePackage( packageName:String ):void | |
| { | |
| _packages[packageName] = packageName; | |
| } | |
| /** | |
| * Unsilences a specified class type | |
| * @param o An instance of the class you wish to unsilence | |
| */ | |
| public static function unsilence( o:* ):void | |
| { | |
| var s:String = getClassName( o ); | |
| _silenced[s] = false; | |
| } | |
| /** | |
| * Unsilences a specified package | |
| * @param packageName The package name you wish to unslience | |
| */ | |
| public static function unsilencePackage( packageName:String ):void | |
| { | |
| delete _packages[packageName]; | |
| } | |
| /** | |
| * Sends an INFO message to the console | |
| * @param origin Origin object | |
| * @param object Message | |
| */ | |
| public static function info( origin:*, object:*, depth:int = 4 ):void | |
| { | |
| output( origin, object, INFO, INFO_COLOR, depth ); | |
| } | |
| /** | |
| * Sends a STATUS message to the console | |
| * @param origin Origin object | |
| * @param object Message | |
| */ | |
| public static function status( origin:*, object:*, depth:int = 4 ):void | |
| { | |
| output( origin, object, STATUS, STATUS_COLOR, depth ); | |
| } | |
| /** | |
| * Sends a DEBUG message to the console | |
| * @param origin Origin object | |
| * @param object Message | |
| */ | |
| public static function debug( origin:*, object:*, depth:int = 4 ):void | |
| { | |
| output( origin, object, DEBUG, DEBUG_COLOR, depth ); | |
| } | |
| /** | |
| * Sends a WARNING message to the console | |
| * @param origin Origin object | |
| * @param object Message | |
| */ | |
| public static function warning( origin:*, object:*, depth:int = 4 ):void | |
| { | |
| output( origin, object, WARNING, WARNING_COLOR, depth ); | |
| } | |
| /** | |
| * Sends an ERROR message to the console | |
| * @param origin Origin object | |
| * @param object Message | |
| */ | |
| public static function error( origin:*, object:*, depth:int = 4 ):void | |
| { | |
| output( origin, object, ERROR, ERROR_COLOR, depth ); | |
| } | |
| /** | |
| * Sends a FATAL message | |
| * @param origin Origin object | |
| * @param object Message | |
| */ | |
| public static function fatal( origin:*, object:*, depth:int = 4 ):void | |
| { | |
| output( origin, object, FATAL, FATAL_COLOR, depth ); | |
| } | |
| /** | |
| * Clears the logger console. | |
| */ | |
| public static function clear():void | |
| { | |
| if( !enabled ) return; | |
| MonsterDebugger.clearTraces(); | |
| } | |
| /** | |
| * Sends a snapshot to the logging console | |
| * @param target | |
| */ | |
| public static function snapshot( target:DisplayObject ):void | |
| { | |
| if( !enabled ) return; | |
| MonsterDebugger.snapshot( target ); | |
| } | |
| private static function output( origin:*, object:*, level:uint = 0, color:uint = 0x000000, depth:int = 4 ):void | |
| { | |
| if( !enabled ) return; | |
| if( !isLevelEnabled( level ) ) return; | |
| if( isSilenced( origin ) ) return; | |
| if( isPackageSilenced( getPackageName( origin ) ) ) return; | |
| MonsterDebugger.trace( origin, object, color, false, depth ); | |
| } | |
| private static function getPackageName( o:* ):String | |
| { | |
| var c:String = getQualifiedClassName( o ); | |
| var s:String = (c == "String" ? o : c.split("::")[0] || c ); | |
| return s; | |
| } | |
| private static function getClassName( o:* ):String | |
| { | |
| var c:String = getQualifiedClassName( o ); | |
| var s:String = (c == "String" ? o : c.split("::")[1] || c ); | |
| return s; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment