Created
May 22, 2015 14:32
-
-
Save ziazon/b68b3bf57ededdcfca75 to your computer and use it in GitHub Desktop.
Javascript Log Function
This file contains hidden or 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
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