Skip to content

Instantly share code, notes, and snippets.

@JemiloII
Last active August 29, 2015 14:13
Show Gist options
  • Save JemiloII/42da090ee8e19189fbda to your computer and use it in GitHub Desktop.
Save JemiloII/42da090ee8e19189fbda to your computer and use it in GitHub Desktop.
Logging with color
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