1

If I am running pm2 process for node js app in fork mode , The logs are getting generated but same app is not giving logs if running in pm2 cluster mode

I am using the below pm2 ecosystem file to start my app

module.exports = {
  apps : [
    {
    name: 'test',
    script: <entry_file_path>,
    exec_mode: "cluster",
    instances: 1,
    autorestart: true,
    watch: false,
    combine_logs:true,
    max_memory_restart: '1G',
    exp_backoff_restart_delay: 1000,
    merge_logs: true,
    env: {
      NODE_ENV: 'production'
    }
  }]
};

I am using log4js v5.2.2 for logging in my node app

6
  • does this help?
    – MAS
    Oct 12, 2020 at 9:21
  • @MAS tried adding pm2:true in log4js configuration and updated the log4js to latest version 6.x.x along with installing pm2-intercom but still can't see the logs
    – shadman140
    Oct 13, 2020 at 5:20
  • did you install pm2-intercom?
    – MAS
    Oct 13, 2020 at 7:24
  • @MAS thanks! that link helped, I am now getting the logs
    – shadman140
    Oct 13, 2020 at 8:53
  • and it is working without pm2-intercom
    – shadman140
    Oct 13, 2020 at 8:54

1 Answer 1

3

Based on suggestion of @MAS below configuration worked for me

run this command "pm2 install pm2-intercom" & then add pm2: true in log4js config

log4js.configure({
  appenders: { out: { type: 'stdout'}},
  categories: { default: { appenders: ['out'], level: 'info'}},
  pm2: true
});

for more details refer https://github.com/log4js-node/log4js-node/blob/master/docs/clustering.md

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.