Unitech / pm2

Node.js Production Process Manager with a built-in Load Balancer.
https://pm2.keymetrics.io/docs/usage/quick-start/
Other
41.31k stars 2.61k forks source link

PM2 logs everything to pm2.log #4916

Open 7HUND3RX opened 3 years ago

7HUND3RX commented 3 years ago

What's going wrong?

Anything my node js app logs goes straight to the daemon log (pm2.log) instead of going to the process's log file. For multiple processes, all of them go to pm2.log

How could we reproduce this issue?

Supporting information

--- PM2 report ----------------------------------------------------------------
Date                 : Fri Nov 13 2020 08:28:36 GMT+0000 (Coordinated Universal Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 4.4.0
node version         : 14.8.0
node path            : /usr/bin/pm2
argv                 : /usr/bin/node,/usr/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : ubuntu
uid                  : 1000
gid                  : 1000
uptime               : 53min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 4.4.0
node version         : 14.8.0
node path            : /usr/bin/pm2
argv                 : /usr/bin/node,/usr/bin/pm2,report
argv0                : node
user                 : ubuntu
uid                  : 1000
gid                  : 1000
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : Intel(R) Xeon(R) CPU E5-2686 v4 @ 2.30GHz
cpus nb              : 1
freemem              : 1047068672
totalmem             : 2081546240
home                 : /home/ubuntu
===============================================================================
--- PM2 list -----------------------------------------------
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0  │ mbl-api            │ cluster  │ 0    │ online    │ 0.2%     │ 45.8mb   │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/home/ubuntu/.pm2/pm2.log last 20 lines:
PM2        | Connected to database MONGO
PM2        | Listening to 3000
PM2        | No metadata found. There is more than once class-validator version installed probably. You need to flatten your dependencies.
PM2        | No metadata found. There is more than once class-validator version installed probably. You need to flatten your dependencies.
PM2        | No metadata found. There is more than once class-validator version installed probably. You need to flatten your dependencies.
PM2        | No metadata found. There is more than once class-validator version installed probably. You need to flatten your dependencies.
PM2        | No metadata found. There is more than once class-validator version installed probably. You need to flatten your dependencies.
PM2        | No metadata found. There is more than once class-validator version installed probably. You need to flatten your dependencies.
PM2        | No metadata found. There is more than once class-validator version installed probably. You need to flatten your dependencies.
PM2        | No metadata found. There is more than once class-validator version installed probably. You need to flatten your dependencies.
PM2        | No metadata found. There is more than once class-validator version installed probably. You need to flatten your dependencies.
PM2        | No metadata found. There is more than once class-validator version installed probably. You need to flatten your dependencies.
PM2        | [nodemon] restarting due to changes...
PM2        | [nodemon] starting `npm run dev:start`
PM2        | 
PM2        | > @mbl/api@0.0.1 dev:start /home/ubuntu/mbl-api
PM2        | > node --loader ts-node/esm --experimental-specifier-resolution=node --experimental-top-level-await --no-warnings src/server.ts
PM2        | 
PM2        | Connected to database MONGO
PM2        | Listening to 3000
coldshine commented 3 years ago

I have the same issue.

siftd106 commented 3 years ago

I am experiencing this issue as well. Seems to be related to when instances number is specified in the ecosystem file (or probably the cli).

siftd106 commented 3 years ago

@7HUND3RX If you change your exec_mode to fork, does that fix your problem?

7HUND3RX commented 3 years ago

@siftd106 Yes, it works well in the fork mode

soarding commented 3 years ago

in cluster mode, I have the same ploblem.

nadavye commented 2 years ago

I have the same issue in cluster mode. Did anyone manage to fix that?

coldshine commented 2 years ago

I have the same issue in cluster mode. Did anyone manage to fix that?

I've fixed it by moving pm2 configs into pm2.config.json like so:

{
  "apps": [
    {
      "name": "project-name",
      "script": "./index.ts",
      "instances": "2",
      "exec_mode": "cluster",
      "interpreter": "node",
      "interpreter_args": "-r ts-node/register/transpile-only -r tsconfig-paths/register" 
    }
  ]
}

What I did is copy-pasted working example from pm2 repo https://github.com/Unitech/pm2/blob/master/examples/cluster-http/ecosystem.config.js and adjusted the config to my project. As far as I remember - the crusial part was to specify "exec_mode": "cluster" param in this config. Dunno why, but it didn't work with console command param in my case (pm2 start app.js -i max).

xgalen commented 5 months ago

Same issue is happening to me in cluster mode.