Skip to content

Instantly share code, notes, and snippets.

@mikeatlas
Created September 8, 2016 20:11
Show Gist options
  • Save mikeatlas/92dfd205d9a5c4755349e7c29a46fd0e to your computer and use it in GitHub Desktop.
Save mikeatlas/92dfd205d9a5c4755349e7c29a46fd0e to your computer and use it in GitHub Desktop.
Overrides the console.log (specifically this is for node.js) with an ISO timestamp prefix and still handles string interpolation formats.
function showDate(){
var date = new Date(), str = date.toISOString();
return str;
}
function formatArgs(args){
return util.format.apply(util.format, Array.prototype.slice.call(args));
}
var origLog = console.log;
console.log = function() {
var strDate = " [ " + showDate() + " ] ";
var logString = strDate + formatArgs(arguments);
origLog(logString);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment