Last active
August 29, 2015 14:13
-
-
Save JemiloII/42da090ee8e19189fbda to your computer and use it in GitHub Desktop.
Logging with color
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
var colors = require('colour'), | |
setTheme = ['silly', 'input', 'verbose', 'prompt', 'info', 'data', 'help', 'warn', 'debug', 'error']; | |
colors.setTheme({ | |
silly: 'rainbow', | |
input: 'grey', | |
verbose: 'cyan', | |
prompt: 'grey', | |
info: 'green', | |
data: 'grey', | |
help: 'cyan', | |
warn: ['yellow', 'underline'], | |
debug: 'blue', | |
error: 'red bold' | |
}); | |
setTheme.forEach(function(item){ | |
if(item === 'log'){ return console.log('warn: Cannot setTheme for log!'.warn); } | |
console[item] = { | |
log: function(){ | |
var i = 0, list = ''; | |
while(i<arguments.length) { | |
list += arguments[i] + ' '; | |
i+=1; | |
} | |
if(process.argv.indexOf('--'+item)>-1) { | |
return console.log(item.toString()[item] + ': '[item] + list); | |
}else{ | |
return void 0; | |
} | |
} | |
}; | |
}); | |
console.silly.log('Testing Silly'); | |
console.warn.log('Testing Warn'); | |
console.debug.log('Testing Debug'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment