Skip to content

Instantly share code, notes, and snippets.

@ziazon
Created May 22, 2015 14:32
Show Gist options
  • Save ziazon/b68b3bf57ededdcfca75 to your computer and use it in GitHub Desktop.
Save ziazon/b68b3bf57ededdcfca75 to your computer and use it in GitHub Desktop.
Javascript Log Function
function Log() {
var escape = "\033";
var colors = {
"yellow": escape + "[33m",
"green": escape + "[32m",
"red": escape + "[31m",
"reset": escape + "[0m"
};
var typesMap = {
"info": colors.yellow,
"success": colors.green,
"error": colors.red
};
if (!arguments[1]) arguments[1] = "info";
if( typeof arguments[0] === 'object' ) {
arguments[0] = typesMap[arguments[1]] + JSON.stringify(arguments[0]) + colors.reset;
}
if ( typeof arguments[0] === 'string' ) {
arguments[0] = typesMap[arguments[1]] + arguments[0] + colors.reset;
}
var args = Array.prototype.slice.call(arguments);
args.splice(1,1);
console.log.apply(this, args);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment