Skip to content

Instantly share code, notes, and snippets.

@daniellizik
Created April 22, 2016 16:04
Show Gist options
  • Save daniellizik/f816655f3d9951c63cf4887bfbbce83d to your computer and use it in GitHub Desktop.
Save daniellizik/f816655f3d9951c63cf4887bfbbce83d to your computer and use it in GitHub Desktop.
colorful logging in chrome
(function(root, name, factory) {
root[name] = factory();
})(this, 'Log', function() {
'use strict';
/**
* @constructor Log
* logs pretty, easy
*
* @param {string} - message to log
* @param {object<...object>} - styles to apply to message, uses style hash
*/
function Log() {
var args = [].slice.call(arguments);
this.styles = args.slice(1);
this.msg = args[0];
this.chromeStyle = [this.msg];
}
/**
* @methodof Log
*
* logs pretty to chrome, message passed to constructor needs to follow %c syntax
*/
Log.prototype.chrome = function() {
var i = 0, p, str = '';
for (i; i < this.styles.length; i++) {
for (p in this.styles[i])
str += (p + ':' + this.styles[i][p] + ';');
this.chromeStyle.push(str);
}
console.log.apply(console, this.chromeStyle)
};
return Log;
});
!function(s,t,e){s[t]=e()}(this,"Log",function(){"use strict";function s(){var s=[].slice.call(arguments);this.styles=s.slice(1),this.msg=s[0],this.chromeStyle=[this.msg]}return s.prototype.chrome=function(){var s,t=0,e="";for(t;t<this.styles.length;t++){for(s in this.styles[t])e+=s+":"+this.styles[t][s]+";";this.chromeStyle.push(e)}console.log.apply(console,this.chromeStyle)},s});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment