Last active
December 12, 2016 14:08
-
-
Save SteveBidenko/028e83265639bb63a060ff944e12a44b to your computer and use it in GitHub Desktop.
colorize console.log and add timestamps
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('cli-color'), | |
mapping = { | |
log: colors.yellow, | |
info: colors.green, | |
error: colors.red | |
}; | |
// Change calls of the object console | |
['log', 'info', 'error'].forEach(function(method) { | |
var oldMethod = console[method].bind(console); | |
console[method] = function() { | |
var timeNow = new Date().toLocaleString('en-US', {hour12: false, timeZone: 'Europe/Kiev'}), | |
extArgs = arguments, | |
arguments = Object.keys(extArgs).map(function(key) { return extArgs[key]; }); | |
oldMethod.apply(console, [mapping[method](timeNow + ':')].concat(arguments)); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment