Skip to content

Instantly share code, notes, and snippets.

@pincheira
Created May 18, 2012 08:58
Show Gist options
  • Save pincheira/2724082 to your computer and use it in GitHub Desktop.
Save pincheira/2724082 to your computer and use it in GitHub Desktop.
Custom override console.log to display date on every return string
function showDate(){
var date = new Date(),
str = date.toUTCString();
return str;
}
var orig = console.log;
console.log = function() {
var msgs = [];
while(arguments.length) {
msgs.push("[" + showDate() + "]" + ': ' + [].shift.call(arguments));
}
orig.apply(console, msgs);
};
@pincheira
Copy link
Author

Example:

console.log("Loaded data from JSON");

It will look like this on the console:
Screenshot

@aswin123asd
Copy link

hint= n = 10

console.log((function f(n)
{return ((n>1)? n*f(n-1):n)})(10))

which value return?

@moofMonkey
Copy link

moofMonkey commented Jul 30, 2018

Improved:

{
	var orig = console.log

	console.log = function log() {
		orig.apply(console, [`[${new Date().toISOString().replace("T", " ").replace(/\..+/, "")}]`, ...arguments])
	}
}

@sueblue
Copy link

sueblue commented Jan 17, 2019

mark

@kurdtpage
Copy link

Chrome DevTools has this built in. Go to 3 dots (top right) > settings > Console > Show timestamps
timestamp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment