`pm2 logs <namespace id> --lines 0` outputs nothing
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript, node.js
- Domain
- cli
Research direction
Start in lib/API/LogManagement.js around the lines === 0 check, then inspect the namespace filtering in lib/API/Log.js. Reproduce pm2 logs <namespace id> --lines 0 with a namespaced process and compare it with regular namespace logging. Done means the command streams matching namespace messages, including processes started later, without emitting unrelated process logs.
Written by the indexing model from the issue text.
Description
What's going wrong?
I've been playing around with adopting the use of namespaces to get logs for some subgroup of a local dev environment, namely for webpack run via pm2. However when I tried it out alongside our existing usage of --lines 0 (as we spawn the logs likely before the apps start), I saw nothing.
How could we reproduce this issue?
Should be fairly trivial to reproduce.
Supporting information
I'm fairly certain I've tracked down the source of the issue, and I can put up a PR once I find the time.
The problem is that we check for lines === 0 before we do any logic for namespaces: https://github.com/Unitech/pm2/blob/311c53298448fc4575fc689c4943692a664373ad/lib/API/LogManagement.js#L171-L172
However, I don't think the answer is to move that logic lower so that we can utilize the computed namespaceList, since that's not even passed to Log.stream on L260. Instead, we can use the information we already have, and update this conditional: https://github.com/Unitech/pm2/blob/311c53298448fc4575fc689c4943692a664373ad/lib/API/Log.js#L101-L104
I.e. we'd update it to be something like
if (id !== 'all'
&& packet.process.name != id
&& packet.process.pm_id != id
&& packet.process.namespace != id)
I think this is preferable because if we utilized namespaceList we'd run afoul of another bug, namely that processes that're started later on don't get included in pm2 logs <namespace id> with the current implementation. But if we filtered the messages as they come in via the bus, we avoid bugs from computing and storing a list of processes that could become stale.
--- 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: ===============================================================================
- Dominant language
- JavaScript
- Stars
- 43.3k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
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.
More from Unitech/pm2
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
-
Errors Open
Difficulty 4/5 3-5 days Newbie friendliness 28/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Similar issues
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
optimization optimization:agents-md-curator
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
githubnext/gh-aw-cao#13143 ·
-
status: needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100