Skip to content

Instantly share code, notes, and snippets.

@SteveBidenko
Last active December 12, 2016 14:08
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 SteveBidenko/028e83265639bb63a060ff944e12a44b to your computer and use it in GitHub Desktop.
Save SteveBidenko/028e83265639bb63a060ff944e12a44b to your computer and use it in GitHub Desktop.
colorize console.log and add timestamps
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