Skip to content

Instantly share code, notes, and snippets.

@autocircled
Created January 17, 2025 06:18
Show Gist options
  • Save autocircled/b52ef9e16d498cb0b76a49bf87c875ae to your computer and use it in GitHub Desktop.
Save autocircled/b52ef9e16d498cb0b76a49bf87c875ae to your computer and use it in GitHub Desktop.
use console.log with stack trace
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