`pm2 logs <regex or namespace>` doesn't account for processes started after
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 43.3k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
What's going wrong?
The list of processes matching regex/namespace become stale, i.e. newly started processes don't get included: https://github.com/Unitech/pm2/blob/311c53298448fc4575fc689c4943692a664373ad/lib/API/LogManagement.js#L163-L164
Whereas running pm2 logs will show logs from all processes, even ones started after the pm2 logs command was run.
How could we reproduce this issue?
Should be trivial to reproduce - I cannot think of anything to provide to help with reproducing.
Supporting information
I'm fairly certain this can be solved by doing the filtering logic inside the bus.on('logs:*', ...) callback, rather than on startup like is done here: https://github.com/Unitech/pm2/blob/311c53298448fc4575fc689c4943692a664373ad/lib/API/LogManagement.js#L249-L261
I'll try to create a PR for that once I can find time.
PM2 report
--- PM2 report ----------------------------------------------------------------
Date : Fri Aug 18 2023 17:12:09 GMT-0700 (Pacific Daylight Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version : 5.3.0
node version : 16.17.1
node path : not found
argv : /Users/bryan/src/coda/build/node-v16.17.1-darwin-x64/bin/node,/Users/bryan/src/coda/node_modules/.pnpm/pm2@5.3.0_patch_hash=pzool4mgrkkjf3a4ff3havxysq/node_modules/pm2/lib/Daemon.js
argv0 : node
user : bryan
uid : 503
gid : 20
uptime : 0min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 5.3.0
node version : 16.17.1
node path : not found
argv : /Users/bryan/src/coda/build/node-v16.17.1-darwin-x64/bin/node,/Users/bryan/src/coda/node_modules/pm2/bin/pm2,report
argv0 : node
user : bryan
uid : 503
gid : 20
===============================================================================
--- System info --------------------------------------------
arch : x64
platform : darwin
type : Darwin
cpus : Apple M1 Max
cpus nb : 10
freemem : 7747424256
totalmem : 68719476736
home : /Users/bryan
===============================================================================
--- PM2 list -----------------------------------------------
┌────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
└────┴───────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/Users/bryan/.pm2/pm2.log last 20 lines:
PM2 | 2023-08-18T17:12:08: PM2 log: pid=7397 msg=process killed
PM2 | 2023-08-18T17:12:08: PM2 log: pid=7383 msg=process killed
PM2 | 2023-08-18T17:12:08: PM2 log: pid=7285 msg=process killed
PM2 | 2023-08-18T17:12:08: PM2 log: PM2 successfully stopped
PM2 | 2023-08-18T17:12:09: PM2 log: ===============================================================================
PM2 | 2023-08-18T17:12:09: PM2 log: --- New PM2 Daemon started ----------------------------------------------------
PM2 | 2023-08-18T17:12:09: PM2 log: Time : Fri Aug 18 2023 17:12:09 GMT-0700 (Pacific Daylight Time)
PM2 | 2023-08-18T17:12:09: PM2 log: PM2 version : 5.3.0
PM2 | 2023-08-18T17:12:09: PM2 log: Node.js version : 16.17.1
PM2 | 2023-08-18T17:12:09: PM2 log: Current arch : x64
PM2 | 2023-08-18T17:12:09: PM2 log: PM2 home : /Users/bryan/.pm2
PM2 | 2023-08-18T17:12:09: PM2 log: PM2 PID file : /Users/bryan/.pm2/pm2.pid
PM2 | 2023-08-18T17:12:09: PM2 log: RPC socket file : /Users/bryan/.pm2/rpc.sock
PM2 | 2023-08-18T17:12:09: PM2 log: BUS socket file : /Users/bryan/.pm2/pub.sock
PM2 | 2023-08-18T17:12:09: PM2 log: Application log path : /Users/bryan/.pm2/logs
PM2 | 2023-08-18T17:12:09: PM2 log: Worker Interval : 30000
PM2 | 2023-08-18T17:12:09: PM2 log: Process dump file : /Users/bryan/.pm2/dump.pm2
PM2 | 2023-08-18T17:12:09: PM2 log: Concurrent actions : 2
PM2 | 2023-08-18T17:12:09: PM2 log: SIGTERM timeout : 1600
PM2 | 2023-08-18T17:12:09: PM2 log: ===============================================================================
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 in lib/API/LogManagement.js at the process filtering around lines 163-164 and the bus.on('logs:*', ...) callback around lines 249-261. Run pm2 logs <regex or namespace>, start a matching process afterward, and verify its logs are included. Done means filtered log sessions also include matching processes started after the command begins.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100