pm2 logs isssue with nyc
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 43.3k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
I am trying to use pm2 to run a JS file with NYC.
The pm2 "exec_mode" is set to cluster "cluster", we have to use this configuration.
We run pm2 with the following config (ecosystem-run-nyc.json, attached):
{
"apps": [
{
"name": "my-nyc-wrapper",
"script": "node_modules/nyc/bin/nyc.js",
"instances": 1,
"exec_mode": "cluster",
"shutdown_with_message": true,
"args": [
"node",
"index.js"
],
"watch": false,
"node_args": "--max_old_space_size=8192",
"out_file": "logs.log",
"error_file": "logs-error.log",
"merge_logs": true,
"env": {
"NODE_ENV": "production",
"NEWRELIC_APM_ENABLED": "false"
}
}
]
}
The problem is that the logs are not associated with the relevant log (by the service name).
Instead of that the logs write to the root pm2 logs.

if I run pm2 monit it looks like I don`t have any logs for this specific service.

I attached here here the full example to nyc-logs-error.zip
If I changed the mode to "fork" it works fine.
If I try to run the js without nyc it works fine too.
pm2 version : 5.1.2
node version : v16.13.0
thx
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
Start with the attached ecosystem-run-nyc.json configuration and reproduce the behavior using PM2 5.1.2 with Node.js v16.13.0. Compare cluster and fork modes, and runs with and without NYC; done means NYC output is associated with the service logs and appears correctly in pm2 monit rather than the root PM2 logs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- cli, devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100