Intercept console.log but keep the stack

I know that it is easy to intercept a function in js, among other things:

console.log = (function () {
var log = console.log;

return function () {
    alert(arguments);
    log.apply(console, arguments);
})();

but is there a way to wrap console.log so that when calling the user

console.log("hi")//in random.js

does the random.js source appear in the console, and not the capture location?

+2
source share
1 answer

Use try/catchinstead of returning a function:

console.log = Function("a", "try { console.info(a); } catch(e){return e}");
0
source

All Articles