diff --git a/lib/log4js.js b/lib/log4js.js index cbbb004..7bce895 100644 --- a/lib/log4js.js +++ b/lib/log4js.js @@ -211,7 +211,7 @@ function configure(configurationFileOrObject) { // just in case configure is called after shutdown process.removeListener('message', receiver); - if (cluster) { + if (cluster && !config.disableClustering) { cluster.removeListener('message', receiver); } if (config.disableClustering) { diff --git a/test/tap/passenger-test.js b/test/tap/passenger-test.js new file mode 100644 index 0000000..c1842b4 --- /dev/null +++ b/test/tap/passenger-test.js @@ -0,0 +1,51 @@ +const test = require('tap').test; +const sandbox = require('sandboxed-module'); + +// passenger provides a non-functional cluster module, +// but it does not implement the event emitter functions +// this is taken from https://github.com/phusion/passenger/blob/82bef697c0019c034faeb9b0f8c08a43ec4e1e22/src/helper-scripts/node-loader.js#L64 +const passengerCluster = { + disconnect: function () { return false; }, + fork: function () { return false; }, + setupMaster: function () { return false; }, + isWorker: true, + isMaster: false, + schedulingPolicy: false, + settings: false, + worker: false, + workers: false, +}; + +const vcr = require('../../lib/appenders/recording'); + +const log4js = sandbox.require( + '../../lib/log4js', + { + requires: { + cluster: passengerCluster, + './appenders/recording': vcr + } + } +); + +test('When running in Passenger', (batch) => { + batch.test('it should still log', (t) => { + log4js.configure({ + appenders: { + vcr: { type: 'recording' } + }, + categories: { + default: { appenders: ['vcr'], level: 'info' } + }, + disableClustering: true + }); + log4js.getLogger().info('This should still work'); + + const events = vcr.replay(); + t.equal(events.length, 1); + t.equal(events[0].data[0], 'This should still work'); + t.end(); + }); + + batch.end(); +});