Problem of Dispatching log to different PM2 cluster master
I run multiple PM2 cluster services in one PM2 instance and every service has a different pm2 'instance_var' name config. And every log4js config in the pm2 service has a correspond 'pm2InstanceVar' name config.
When the services run, the logs just merge together.
I think log4js can find the master process of each cluster service, but every master process prints all cluster services's logs.
How about make a cluster worker send log message with the instance_var in the message. Then the master process will know which log should be ignored.
Hi, thanks for raising this. It looks to be the same issue as #547. It's something we will be looking at once we get version 3.x of log4js released.
I just wrote https://github.com/liujingbreak/log4js-pm2-intercom to resolve this problem, but yet not fully tested, so maybe you can try out and help to test it.
@nomiddlename Any process or workaround solution? I has this problem too. PM2 cluster mode uncompatible with log4js, that means pm2 can not use at production?
@sinbargit You could give the module that @liujingbreak has written a try. I will take a look at this, but currently my focus is on the version-3.x release to remove the security complaints from the optional dependencies.
i has get the problem like this:i am run my nodejs app an use pm2 is cluster mode,but my app can not write the log by log4js.

my app log4js code :
const log4js = require('log4js');
const logconfig = require('../../config');
log4js.configure({
appenders: {
cheese: logconfig.log4js
},
categories: { default: { appenders: ['cheese'], level: 'trace' } }
});
const logger = log4js.getLogger('cheese');
module.exports =logger;
config:
...
log4js: {
type: "dateFile",
filename: './server/logs/log',
alwaysIncludePattern: true,
pattern: "-yyyy-MM-dd.log",
category: "log_date",
encoding: 'utf-8'//default "utf-8",文件的编码
}
...