Skip to content

Instantly share code, notes, and snippets.

@voidstar0
Created October 7, 2025 21:07
Show Gist options
  • Select an option

  • Save voidstar0/179990efe918d1028b72f292cfafe500 to your computer and use it in GitHub Desktop.

Select an option

Save voidstar0/179990efe918d1028b72f292cfafe500 to your computer and use it in GitHub Desktop.
console.log.toString() // Returns 'function log() { [native code] }'
const consoleHandler = {
get(target, property, receiver) {
if (property === 'log') {
return function(...args) {
const newArgs = ['[LOG]:', ...args];
return Reflect.apply(target[property], target, newArgs);
};
}
// For any other property (e.g., 'warn', 'error', 'table'),
// we just want the default behavior. Reflect.get does that.
return Reflect.get(target, property, receiver);
}
};
window.console = new Proxy(console, consoleHandler);
console.log.toString() // Returns "function(...args) {\n const newArgs = ['[LOG]:', ...args];\n return Reflect.apply(target[property], target, newArgs);\n }"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment