Skip to content

Instantly share code, notes, and snippets.

@rlucha
Forked from FGRibreau/console_patch.js
Created December 9, 2015 08:29
Show Gist options
  • Save rlucha/ca6fdf98f25b8ee4af27 to your computer and use it in GitHub Desktop.
Save rlucha/ca6fdf98f25b8ee4af27 to your computer and use it in GitHub Desktop.
Add timestamp information to the JavaScript console
/**
* Patch the console methods in order to provide timestamp information
*
* Usage:
* > console.log('ok')
* 2012-09-06T11:52:56.769Z ok true
*
* Note:
* The patch will only be applied with the first call.
*
* Tested with V8 (Google Chrome & NodeJS)
*/
(function(o){
if(o.__ts__){return;}
var slice = Array.prototype.slice;
['log', 'debug', 'info', 'warn', 'error'].forEach(function(f){
var _= o[f];
o[f] = function(){
var args = slice.call(arguments);
args.unshift(new Date().toISOString());
return _.apply(o, args);
};
});
o.__ts__ = true;
})(console);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment