1

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

Fifi
  • 3,360
  • 2
  • 27
  • 53
  • Would running the node.js program inside another program (kind of like how PM2 and Forever works) be an option? This technique would work with any language - Java, C, assembly, node.js etc. – slebetman Jan 13 '20 at 04:45
  • 1
    It's a client side question. – Fifi Jan 13 '20 at 06:36

1 Answers1

1

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)))
Lux
  • 17,835
  • 5
  • 43
  • 73