Skip to content

Instantly share code, notes, and snippets.

@TigerC10
Last active October 11, 2016 22:45
Show Gist options
  • Save TigerC10/13ed6ec06beb550ad219c6cc69e14d09 to your computer and use it in GitHub Desktop.
Save TigerC10/13ed6ec06beb550ad219c6cc69e14d09 to your computer and use it in GitHub Desktop.
My new favorite logging snippet for NodeJS
(function () {
var resetColor = '\x1b[0m';
if (typeof module !== 'undefined' && module.exports) {
[
['log', '\x1b[0m'],
['info', '\x1b[36m'],
['warn', '\x1b[33m'],
['error', '\x1b[31m'],
].forEach(function(level) {
var method = level[0];
var color = level[1];
console[method] = console[method].bind(console, color, method.toUpperCase(), resetColor);
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment