Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pm2 logs <namespace id> --lines 0 outputs nothing #5658

Open
bryan-codaio opened this issue Aug 19, 2023 · 0 comments
Open

pm2 logs <namespace id> --lines 0 outputs nothing #5658

bryan-codaio opened this issue Aug 19, 2023 · 0 comments

Comments

@bryan-codaio
Copy link

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:

if (lines === 0)
return Log.stream(that.Client, id, raw, timestamp, exclusive, highlight);

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:

pm2/lib/API/Log.js

Lines 101 to 104 in 311c532

if (id !== 'all'
&& packet.process.name != id
&& packet.process.pm_id != id)
return;

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: ===============================================================================

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant