log4js-node icon indicating copy to clipboard operation
log4js-node copied to clipboard

Problem of Dispatching log to different PM2 cluster master

Open zhjjj opened this issue 7 years ago • 5 comments

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.

zhjjj avatar Jun 02 '18 15:06 zhjjj

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.

nomiddlename avatar Jun 03 '18 21:06 nomiddlename

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.

liujingbreak avatar Jul 03 '18 11:07 liujingbreak

@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 avatar Jul 10 '18 07:07 sinbargit

@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.

nomiddlename avatar Jul 11 '18 21:07 nomiddlename

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. image

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",文件的编码
    }
...

xulayen avatar Mar 28 '19 11:03 xulayen