is it possible to make an on(consolelog event? it would do something every time text is logged to console

Tags: ,



This feature would do something every time text is logged to the node.js console.
Here’s a somewhat of example of how I think it should look like:

on('console', msg => {console.log("text was logged! " + msg)})

Regular node.js

Answer

Console methods don’t emit events, but the console object and its methods can be overwritten, so you could redefine it yourself: console.log = (...args) => { process.stdout.write('logged: ' + args.join(' ')) }, or wrap it in a Proxy.



Source: stackoverflow