github.com/atsaki/terraform@v0.4.3-0.20150919165407-25bba5967654/website/source/assets/javascripts/lib/dbg.js (about)

     1  /*
     2   *
     3   *	name: dbg
     4   *
     5   *	description: A bad ass little console utility, check the README for deets
     6   *
     7   *	license: MIT-style license
     8   *
     9   *	author: Amadeus Demarzi
    10   *
    11   *	provides: window.dbg
    12   *
    13   */
    14  
    15  (function(){
    16  
    17  	var global = this,
    18  
    19  		// Get the real console or set to null for easy boolean checks
    20  		realConsole = global.console || null,
    21  
    22  		// Backup / Disabled Lambda
    23  		fn = function(){},
    24  
    25  		// Supported console methods
    26  		methodNames = ['log', 'error', 'warn', 'info', 'count', 'debug', 'profileEnd', 'trace', 'dir', 'dirxml', 'assert', 'time', 'profile', 'timeEnd', 'group', 'groupEnd'],
    27  
    28  		// Disabled Console
    29  		disabledConsole = {
    30  
    31  			// Enables dbg, if it exists, otherwise it just provides disabled
    32  			enable: function(quiet){
    33  				global.dbg = realConsole ? realConsole : disabledConsole;
    34  			},
    35  
    36  			// Disable dbg
    37  			disable: function(){
    38  				global.dbg = disabledConsole;
    39  			}
    40  
    41  		}, name, i;
    42  
    43  	// Setup disabled console and provide fallbacks on the real console
    44  	for (i = 0; i < methodNames.length;i++){
    45  		name = methodNames[i];
    46  		disabledConsole[name] = fn;
    47  		if (realConsole && !realConsole[name])
    48  			realConsole[name] = fn;
    49  	}
    50  
    51  	// Add enable/disable methods
    52  	if (realConsole) {
    53  		realConsole.disable = disabledConsole.disable;
    54  		realConsole.enable = disabledConsole.enable;
    55  	}
    56  
    57  	// Enable dbg
    58  	disabledConsole.enable();
    59  
    60  }).call(this);