Cluster mode and npm start directs to wrong logs
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 43.3k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
- Installed PM2 version:
"pm2": "^2.10.4", - Node version:
6.11.1(latest 6.x available on AWS)
When exec mode is set to cluster, and the script is set to npm start or npm run start, logs for each application (console.log tested at the moment), are directed to the global PM2 log.
Expected behavior is that logs that are from the stream of individual applications are still written to each application logs.
Scenarios
✔️ This setup shows works and has no problem. The console.log outputs on each of the application's logs
exec_mode: 'cluster'script: 'index.js'

❌ This setup directs all console.log to the global PM2 log, and not on each application log files
exec_mode: 'cluster'script: 'npm', args: 'start',

As you can see at the end of the global PM2 log, that's where the application console.log outputs are.
⚠️ Fork mode setup somehow works even with npm start, but runs the script twice per app, not sure what's up.
exec_mode: 'fork'script: 'npm', args: 'start',

I have no interest in using the fork-npm setup at the moment, but you might want to look at it as well.
Script
If needed, here's the only content of the index.js being ran
const config = require('config')
console.log('SERVICE',
process.env.NODE_SERVICE,
process.env.NODE_PORT,
process.env.NODE_INSTANCE_ID,
new Date().toString(),
JSON.stringify(config)
)
Notes
- I have also tried
--no-daemonfor the pm2 args, but same problempm2 start ecosystem.config.js --no-daemon
- The
startscript inside package json is just"start": "node .",
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the cluster-mode case using ecosystem.config.js, the package.json start script, and the shown index.js, then compare it with the direct index.js setup and fork mode. Trace PM2's log handling for the npm start entry point; done means each clustered application's console output appears in its own application log rather than the global PM2 log.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- cli, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100