Created
October 25, 2022 09:15
-
-
Save korrio/a93260c3335c8b36a3ae749aa3772776 to your computer and use it in GitHub Desktop.
Add timestamp to all subsequent console.logs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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