Fifi
Fifi

Reputation: 3605

Capturing JavaScript console.log console.dir, console.table

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

Answers (1)

Lux
Lux

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

Related Questions