Skip to content

Instantly share code, notes, and snippets.

@hayatbiralem
Created November 6, 2015 13:42
Show Gist options
  • Save hayatbiralem/ad7b720f4c1c9299e04a to your computer and use it in GitHub Desktop.
Save hayatbiralem/ad7b720f4c1c9299e04a to your computer and use it in GitHub Desktop.
Log function for Chrome Console
var debug = true;
var log = function(type){ debug && window.console && console[( type in console ? type : 'log' )].apply(console, Array.prototype.slice.call(arguments, ( type in console ? 1 : 0 ))); };
@hayatbiralem
Copy link
Author

Easy grouping:

var debug = true;
var log = function(type){ debug && window.console && console[( type in console ? type : 'log' )].apply(console, Array.prototype.slice.call(arguments, ( type in console ? 1 : 0 ))); };
var that = this;
var logGroup = function(name, logs){
    log('group', name);
    for(var i = 0; i < logs.length; i++){ log.apply(that, logs[i]); }
    log('groupEnd');
};

Usage

var result_1 = { 'foo' : 'bar' };
var result_2 = { 'result_1' : result_1 };
logGroup('Results', [['info', result_1], ['info', result_2]]);

Result

Easy Log Grouping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment