pm2 in cluster mode does not show node logs

Viewed 1652

I've been trying to start an express server in pm2 cluster mode. But when I run pm2 logs it does not show any logs produced by the code (console.log or console.error for example).

To illustrate my issue, consider this small snippet of server

const app = require('express')();

app.all('*', (req, res) => {
    console.log('new request recieved');
    res.send();
});

app.listen(3000);

I've tried everything mentioned in pm2 docs. Even specifying the log files does not work.

This is the command I used pm2 start -i 0 --merge-logs npm -- start -o /home/user/.pm2/logs/out.log -e /home/user/.pm2/logs/err.log --name playground

Although the logs are written to a file in ~/.pm2/pm2.log, -e and -o option have no effect.

Right now I have to use tail -f ~/.pm2/pm2.log

I want to be able to see logs when I run pm2 log [app name/id] as I'll be running multiple servers in cluster mode and want the logs to be separate for each cluster of server.

1 Answers

Tested snippet above using pm2 start -i 0 cluser.js and it is working fine. pm2 logs works ok.

pm2 - v4.4.0 node - v12.16.3

tail -f ~/.pm2/pm2.log


2020-06-16T15:37:35: PM2 log: App [cluser:9] online
2020-06-16T15:37:35: PM2 log: App [cluser:11] starting in -cluster mode-
2020-06-16T15:37:35: PM2 log: App [cluser:10] online
2020-06-16T15:37:35: PM2 log: App [cluser:12] starting in -cluster mode-
2020-06-16T15:37:35: PM2 log: App [cluser:11] online
2020-06-16T15:37:35: PM2 log: App [cluser:13] starting in -cluster mode-
2020-06-16T15:37:35: PM2 log: App [cluser:12] online
2020-06-16T15:37:35: PM2 log: App [cluser:14] starting in -cluster mode-
2020-06-16T15:37:35: PM2 log: App [cluser:13] online
2020-06-16T15:37:35: PM2 log: App [cluser:14] online

Related