Skip to content

Instantly share code, notes, and snippets.

@antonlvovych
Last active August 29, 2015 14:18
Show Gist options
  • Save antonlvovych/30574e7650a380b132aa to your computer and use it in GitHub Desktop.
Save antonlvovych/30574e7650a380b132aa to your computer and use it in GitHub Desktop.
Simple console.log wrapper with colors and labels
;(function () {
var options = {
name: 'logger',
label: '❤',
date: true,
color: '#2980b9'
};
window[options.name] = function () {
var label = options.label + (options.date ? ('[' + Date() + ']') : '')
, _arg = [];
label && _arg.push(('%c' + label));
options.color && _arg.push('color:' + options.color);
console.log.apply(console, _arg.concat(Array.prototype.slice.apply(arguments)));
};
})();
/* ~200 bytes */
;(function(){var o={n:"logger",l:"❤",d:!0,c:"#2980b9"};window[o.n]=function(){var l=o.l+(o.d?"["+Date()+"]":""),a=[];l&&a.push("%c"+l);o.c&&a.push("color:"+o.c);console.log.apply(console,a.concat(Array.prototype.slice.apply(arguments)))}})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment