fix(pm2): debug and examples for pm2

This commit is contained in:
Gareth Jones 2017-07-26 09:19:10 +10:00
parent 78d9e3568e
commit 082f0ccede
4 changed files with 16 additions and 2 deletions

View File

@ -9,7 +9,8 @@ log4js.configure({
categories: {
default: { appenders: ['out'], level: 'info' }
},
pm2: true
pm2: true,
pm2InstanceVar: 'INSTANCE_ID'
});
const logger = log4js.getLogger('app');

9
examples/pm2.json Normal file
View File

@ -0,0 +1,9 @@
{ "apps": [
{ "name": "testing",
"script": "pm2.js",
"instances": 0,
"instance_var": "INSTANCE_ID",
"exec_mode": "cluster"
}
]
}

View File

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

View File

@ -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: {} }
}
}
);