Created
January 17, 2025 06:18
-
-
Save autocircled/b52ef9e16d498cb0b76a49bf87c875ae to your computer and use it in GitHub Desktop.
use console.log with stack trace
This file contains hidden or 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
const logger = new Proxy((...message) => { | |
console.log(...message); | |
}, { | |
apply(target, thisArg, argumentsList) { | |
const stack = new Error().stack.split('\n').slice(2, 4).join('\n'); | |
console.log('Logger called with arguments:', argumentsList); | |
console.log('Stack Trace:\n', stack); | |
return target(...argumentsList); | |
} | |
}); | |
export default logger; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment