Unitech / pm2

Node.js Production Process Manager with a built-in Load Balancer.
https://pm2.keymetrics.io/docs/usage/quick-start/
Other
41.4k stars 2.61k forks source link

Do not override console.log #2773

Open sitegui opened 7 years ago

sitegui commented 7 years ago

Expected behaviour

Using PM2 programmatically should not override console.log's native behavior when PM2 daemon is not spawned.

For example, console.log({a: 2}) should print { a: 2 }

Actual behaviour

Utility.overrideConsole() is called

In the example above, 2017-03-16 15:27:05: [object Object] is printed 😞

Steps to reproduce

$ pm2 kill

require('pm2').connect(true, () => console.log({a: 2}))

Software versions used

OS         : Windows 10
node.js    : v6.10.0
PM2        :2.0.12 up to 2.4.2
sitegui commented 7 years ago

Using Object.freeze(console) before pm2.connect() solves it for me now

vmarchaud commented 7 years ago

I believe its coming from this call, we should either implement a custom logger and replace all console call, or calling the overrideConsole only when we are on the daemon process.

sitegui commented 7 years ago

Yes, the code path seems to be:

  1. this.Client.start
  2. require('./Daemon.js')
  3. require('./God')
  4. Utility.overrideConsole(God.bus)