Created
July 2, 2015 12:44
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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