Skip to content

Instantly share code, notes, and snippets.

@korrio
Created October 25, 2022 09:15
Show Gist options
  • Save korrio/a93260c3335c8b36a3ae749aa3772776 to your computer and use it in GitHub Desktop.
Save korrio/a93260c3335c8b36a3ae749aa3772776 to your computer and use it in GitHub Desktop.
Add timestamp to all subsequent console.logs
// Add timestamp to all subsequent console.logs
// One little two little three little dependency injections....
const origLog = console.log;
console.log = function (obj, ...placeholders) {
if (typeof obj === "string")
placeholders.unshift("[" + new Date().toISOString() + "] " + obj);
else {
// This handles console.log( object )
placeholders.unshift(obj);
placeholders.unshift("[" + new Date().toISOString() + "] %j");
}
origLog.apply(this, placeholders);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment