Reputation: 3605
There is already several questions about capturing or redirecting console.log
:
When we need to capture all the console messages (console.log, console.dir, console.table ...), is there a simple way to redirect all the functions without "overloading" each?
Edit: this question is about client-side JavaScript
Upvotes: 1
Views: 476
Reputation: 18240
You can do something like this:
function fake(cb) {
return (...args) => {
... magic capture code...
cb(...args);
}
}
Object.keys(console).forEach(k => console[k] = fake(console[k].bind(console)))
Upvotes: 1