Skip to content

Instantly share code, notes, and snippets.

@arjunu
Created December 22, 2015 10:19
Show Gist options
  • Save arjunu/97d39155d55aed844f3a to your computer and use it in GitHub Desktop.
Save arjunu/97d39155d55aed844f3a to your computer and use it in GitHub Desktop.
(function() {
"use strict";
var colorful_console = function() {
var themes = {
'default': {
error: {
background: "red",
color: "white",
padding: "2px"
},
log: {
background: "grey",
color: "white",
padding: "2px"
},
warn: {
background: "yellow",
color: "black",
padding: "2px"
}
}
};
var currentThemeName = "default";
/** Construct and return style
* @private
* @param type {string}
* @return style {string}
*/
var getStyle = function(type) {
var theme, style;
switch (type) {
case "error":
theme = themes[currentThemeName].error;
style = "background: " + theme.background + "; ";
style += "color: " + theme.color + ";";
style += "padding: " + theme.padding + ";";
break;
case "log":
theme = themes[currentThemeName].log;
style = "background: " + theme.background + "; ";
style += "color: " + theme.color + ";";
style += "padding: " + theme.padding + ";";
break;
case "warn":
theme = themes[currentThemeName].warn;
style = "background: " + theme.background + "; ";
style += "color: " + theme.color + ";";
style += "padding: " + theme.padding + ";";
break;
default:
;
}
return style;
};
//about
this.version = 0.1;
/** Print error messages
* @public
* @param label
* @param message
*/
this.error = function(label, message) {
label = "%c" + label;
console.log(label, getStyle("error"), message);
};
/** Print error messages
* @public
* @param label
* @param message
*/
this.log = function(label, message) {
label = "%c" + label;
console.log(label, getStyle("log"), message);
};
/** Print error messages
* @public
* @param label
* @param message
*/
this.warn = function(label, message) {
label = "%c" + label;
console.log(label, getStyle("warn"), message);
};
return this;
};
if (!window.cc) {
window.cc = new colorful_console();
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment