Skip to content

Instantly share code, notes, and snippets.

@thejefflarson
Created August 31, 2010 22:11
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 thejefflarson/559846 to your computer and use it in GitHub Desktop.
Save thejefflarson/559846 to your computer and use it in GitHub Desktop.
// hi there npm
var doColor
try {
var stdio = require("stdio")
doColor = stdio.isStderrATTY()
} catch (ex) {
doColor = true
}
function colorize (msg, color) {
if (!msg) return "";
if (!doColor) return msg;
return "\033["+color+"m"+msg+"\033[0m";
}
function log(level, color, message, prefix){
if(prefix) message = level.toUpperCase() + " [" + Date() + "]: " + message;
console[level](colorize(message, color))
}
exports.info = function info(message){
log("info", 32, message, true);
}
exports.warn = function info(message){
log("warn", 33, message);
}
exports.error = function info(message){
log("error", 31, message, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment