Skip to content

Instantly share code, notes, and snippets.

@klauskpm
Created July 2, 2015 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klauskpm/5d0cd9d262fc012d9a65 to your computer and use it in GitHub Desktop.
Save klauskpm/5d0cd9d262fc012d9a65 to your computer and use it in GitHub Desktop.
A simple script to easily group and debug what happens in your code.
/**
* Created by klaus.machado on 25/06/2015.
*/
function SimpleDebug()
{
var labels = {
"APP": {
"color": "#000000"
},
"EXAMPLE": {
"color": "#F4F"
},
"DEBUG": {
"color": "#543"
},
"TABLE": {
"color": "#F4FF4F"
}
},
defaultText = " |";
function transformText(label) {
return "%c" + label + defaultText.substr(label.length);
}
function getStyle(label) {
var style = "font-weight: bolder;",
type = labels[label];
for (var obj in type) {
style += obj + ":" + type[obj] + ";";
}
return style;
}
this.start = function(label) {
label = label ? label.toUpperCase() : "APP";
console.groupCollapsed(transformText(label), getStyle(label), "STARTED");
console.time(label);
return this;
};
this.end = function(label) {
label = label ? label.toUpperCase() : "APP";
console.timeEnd(label);
console.groupEnd(transformText(label), getStyle(label), "ENDED");
return this;
};
this.push = function(label, message) {
label = label ? label.toUpperCase() : "APP";
console.log(transformText(label), getStyle(label), message);
return this;
};
this.object = function(label, obj) {
label = label ? label.toUpperCase() : "APP";
console.log(transformText(label) + " %O", obj);
return this;
};
this.table = function(table, name) {
this.push('table', name);
console.table(table);
return this;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment