diff --git a/examples/pm2.js b/examples/pm2.js index e3df67e..5555323 100644 --- a/examples/pm2.js +++ b/examples/pm2.js @@ -9,7 +9,8 @@ log4js.configure({ categories: { default: { appenders: ['out'], level: 'info' } }, - pm2: true + pm2: true, + pm2InstanceVar: 'INSTANCE_ID' }); const logger = log4js.getLogger('app'); diff --git a/examples/pm2.json b/examples/pm2.json new file mode 100644 index 0000000..45ba25b --- /dev/null +++ b/examples/pm2.json @@ -0,0 +1,9 @@ +{ "apps": [ + { "name": "testing", + "script": "pm2.js", + "instances": 0, + "instance_var": "INSTANCE_ID", + "exec_mode": "cluster" + } + ] + } diff --git a/lib/configuration.js b/lib/configuration.js index 2339117..40c5c42 100644 --- a/lib/configuration.js +++ b/lib/configuration.js @@ -76,6 +76,10 @@ class Configuration { debug(`DEPRECATION: Appender ${config.type} exports a shutdown function.`); } + debug(`cluster.isMaster ? ${cluster.isMaster}`); + debug(`pm2 enabled ? ${this.pm2}`); + debug(`pm2InstanceVar = ${this.pm2InstanceVar}`); + debug(`process.env[${this.pm2InstanceVar}] = ${process.env[this.pm2InstanceVar]}`); if (cluster.isMaster || (this.pm2 && process.env[this.pm2InstanceVar] === '0')) { return appenderModule.configure( config, diff --git a/test/tap/configuration-validation-test.js b/test/tap/configuration-validation-test.js index b0fba77..d262f32 100644 --- a/test/tap/configuration-validation-test.js +++ b/test/tap/configuration-validation-test.js @@ -303,7 +303,7 @@ test('log4js configuration validation', (batch) => { '/var/lib/cheese/cheese': testAppender('correct'), }, globals: { - process: { cwd: () => '/var/lib/cheese' } + process: { cwd: () => '/var/lib/cheese', env: {} } } } );