Merge pull request #616 from log4js-node/dep-updates

fix(#614): bumped deps of debug, date-format, streamroller
This commit is contained in:
Gareth Jones 2017-11-18 10:41:57 +11:00 committed by GitHub
commit 7e008b9369
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 1764 additions and 5914 deletions

View File

@ -12,3 +12,5 @@ lib-cov
coverage.html
Makefile
coverage
Gemfile
Gemfile.lock

View File

@ -8,7 +8,7 @@ const debug = require('debug')('log4js:configuration');
let cluster;
try {
cluster = require('cluster'); // eslint-disable-line global-require
cluster = require('cluster'); // eslint-disable-line global-require
} catch (e) {
debug('Clustering support disabled because require(cluster) threw an error: ', e);
}
@ -36,14 +36,11 @@ function anInteger(thing) {
}
class Configuration {
throwExceptionIf(checks, message) {
const tests = Array.isArray(checks) ? checks : [checks];
tests.forEach((test) => {
if (test) {
throw new Error(
`Problem with log4js configuration: (${util.inspect(this.candidate, { depth: 5 })}) - ${message}`
);
throw new Error(`Problem with log4js configuration: (${util.inspect(this.candidate, { depth: 5 })}) - ${message}`);
}
});
}

View File

@ -31,7 +31,7 @@ const layouts = require('./layouts');
let cluster;
try {
cluster = require('cluster'); // eslint-disable-line global-require
cluster = require('cluster'); // eslint-disable-line global-require
} catch (e) {
debug('Clustering support disabled because require(cluster) threw an error: ', e);
}
@ -78,9 +78,8 @@ function setLevelForCategory(category, level) {
debug(`setLevelForCategory: found ${categoryConfig} for ${category}`);
if (!categoryConfig) {
const sourceCategoryConfig = configForCategory(category);
debug(
`setLevelForCategory: no config found for category, found ${sourceCategoryConfig} for parents of ${category}`
);
debug('setLevelForCategory: no config found for category, ' +
`found ${sourceCategoryConfig} for parents of ${category}`);
categoryConfig = { appenders: sourceCategoryConfig.appenders };
}
categoryConfig.level = level;
@ -205,23 +204,22 @@ function configure(configurationFileOrObject) {
LoggingEvent = loggerModule.LoggingEvent;
module.exports.connectLogger = connectModule(config.levels).connectLogger;
// just in case configure is called after shutdown
process.removeListener('message', receiver);
cluster.removeListener('message', receiver);
if (config.disableClustering) {
debug('Not listening for cluster messages, because clustering disabled.');
} else {
} else if (isPM2Master()) {
// PM2 cluster support
// PM2 runs everything as workers - install pm2-intercom for this to work.
// we only want one of the app instances to write logs
if (isPM2Master()) {
debug('listening for PM2 broadcast messages');
process.removeListener('message', receiver);
process.on('message', receiver);
} else if (cluster.isMaster) {
debug('listening for cluster messages');
cluster.removeListener('message', receiver);
cluster.on('message', receiver);
} else {
debug('not listening for messages, because we are not a master process');
}
debug('listening for PM2 broadcast messages');
process.on('message', receiver);
} else if (cluster.isMaster) {
debug('listening for cluster messages');
cluster.on('message', receiver);
} else {
debug('not listening for messages, because we are not a master process');
}
enabled = true;

View File

@ -6,7 +6,7 @@ const debug = require('debug')('log4js:logger');
let cluster;
try {
cluster = require('cluster'); // eslint-disable-line global-require
cluster = require('cluster'); // eslint-disable-line global-require
} catch (e) {
debug('Clustering support disabled because require(cluster) threw an error: ', e);
}

7457
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -39,10 +39,10 @@
"lib": "lib"
},
"dependencies": {
"date-format": "^1.1.0",
"debug": "^2.6.8",
"date-format": "^1.2.0",
"debug": "^3.1.0",
"semver": "^5.3.0",
"streamroller": "^0.6.0"
"streamroller": "^0.7.0"
},
"devDependencies": {
"codecov": "^3.0.0",

View File

@ -32,7 +32,7 @@ test('../../lib/appenders/dateFile', (batch) => {
t.include(contents, 'This should be in the file');
t.match(
contents,
/\[\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3}] \[INFO] default-settings - /
/\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}] \[INFO] default-settings - /
);
t.end();
});
@ -124,7 +124,7 @@ test('../../lib/appenders/dateFile', (batch) => {
t.equal(fileContents.split(EOL).length, 4);
t.match(
fileContents,
/\[\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3}] \[INFO] default-settings - /
/\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}] \[INFO] default-settings - /
);
t.end();
});

View File

@ -36,7 +36,7 @@ test('log4js fileAppender', (batch) => {
t.include(fileContents, `This should be in the file.${EOL}`);
t.match(
fileContents,
/\[\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3}] \[INFO] default-settings - /
/\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}] \[INFO] default-settings - /
);
t.end();
});
@ -63,7 +63,7 @@ test('log4js fileAppender', (batch) => {
t.equal(fileContents.split(EOL).length, 4);
t.match(
fileContents,
/\[\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3}] \[INFO] default-settings - /
/\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}] \[INFO] default-settings - /
);
t.end();
});
@ -84,7 +84,9 @@ test('log4js fileAppender', (batch) => {
// log file of 100 bytes maximum, no backups
log4js.configure({
appenders: {
file: { type: 'file', filename: testFile, maxLogSize: 100, backups: 0 }
file: {
type: 'file', filename: testFile, maxLogSize: 100, backups: 0
}
},
categories: { default: { appenders: ['file'], level: 'debug' } }
});
@ -98,9 +100,7 @@ test('log4js fileAppender', (batch) => {
t.include(fileContents, 'This is the second log message.');
t.equal(fileContents.indexOf('This is the first log message.'), -1);
fs.readdir(__dirname, (e, files) => {
const logFiles = files.filter(
file => file.includes('fa-maxFileSize-test.log')
);
const logFiles = files.filter(file => file.includes('fa-maxFileSize-test.log'));
t.equal(logFiles.length, 2, 'should be 2 files');
t.end();
});
@ -124,7 +124,9 @@ test('log4js fileAppender', (batch) => {
// log file of 50 bytes maximum, 2 backups
log4js.configure({
appenders: {
file: { type: 'file', filename: testFile, maxLogSize: 50, backups: 2 }
file: {
type: 'file', filename: testFile, maxLogSize: 50, backups: 2
}
},
categories: { default: { appenders: ['file'], level: 'debug' } }
});
@ -136,9 +138,7 @@ test('log4js fileAppender', (batch) => {
// give the system a chance to open the stream
setTimeout(() => {
fs.readdir(__dirname, (err, files) => {
const logFiles = files.sort().filter(
file => file.includes('fa-maxFileSize-with-backups-test.log')
);
const logFiles = files.sort().filter(file => file.includes('fa-maxFileSize-with-backups-test.log'));
t.equal(logFiles.length, 3);
t.same(logFiles, [
'fa-maxFileSize-with-backups-test.log',
@ -184,7 +184,9 @@ test('log4js fileAppender', (batch) => {
// log file of 50 bytes maximum, 2 backups
log4js.configure({
appenders: {
file: { type: 'file', filename: testFile, maxLogSize: 50, backups: 2, compress: true }
file: {
type: 'file', filename: testFile, maxLogSize: 50, backups: 2, compress: true
}
},
categories: { default: { appenders: ['file'], level: 'debug' } }
});
@ -195,9 +197,7 @@ test('log4js fileAppender', (batch) => {
// give the system a chance to open the stream
setTimeout(() => {
fs.readdir(__dirname, (err, files) => {
const logFiles = files.sort().filter(
file => file.includes('fa-maxFileSize-with-backups-compressed-test.log')
);
const logFiles = files.sort().filter(file => file.includes('fa-maxFileSize-with-backups-compressed-test.log'));
t.equal(logFiles.length, 3, 'should be 3 files');
t.same(logFiles, [
'fa-maxFileSize-with-backups-compressed-test.log',

View File

@ -35,7 +35,7 @@ test('log4js fileSyncAppender', (batch) => {
t.include(fileContents, `This should be in the file.${EOL}`);
t.match(
fileContents,
/\[\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3}] \[INFO] default-settings - /
/\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}] \[INFO] default-settings - /
);
t.end();
});
@ -55,7 +55,11 @@ test('log4js fileSyncAppender', (batch) => {
// log file of 100 bytes maximum, no backups
log4js.configure({
appenders: { sync: { type: 'fileSync', filename: testFile, maxLogSize: 100, backups: 0 } },
appenders: {
sync: {
type: 'fileSync', filename: testFile, maxLogSize: 100, backups: 0
}
},
categories: { default: { appenders: ['sync'], level: 'debug' } }
});
logger.info('This is the first log message.');
@ -72,9 +76,7 @@ test('log4js fileSyncAppender', (batch) => {
t.test('there should be two test files', (assert) => {
fs.readdir(__dirname, (err, files) => {
const logFiles = files.filter(
file => file.includes('fa-maxFileSize-sync-test.log')
);
const logFiles = files.filter(file => file.includes('fa-maxFileSize-sync-test.log'));
assert.equal(logFiles.length, 2);
assert.end();
});
@ -97,7 +99,11 @@ test('log4js fileSyncAppender', (batch) => {
// log file of 50 bytes maximum, 2 backups
log4js.configure({
appenders: { sync: { type: 'fileSync', filename: testFile, maxLogSize: 50, backups: 2 } },
appenders: {
sync: {
type: 'fileSync', filename: testFile, maxLogSize: 50, backups: 2
}
},
categories: { default: { appenders: ['sync'], level: 'debug' } }
});
logger.info('This is the first log message.');
@ -108,9 +114,7 @@ test('log4js fileSyncAppender', (batch) => {
t.test('the log files', (assert) => {
assert.plan(5);
fs.readdir(__dirname, (err, files) => {
const logFiles = files.filter(
file => file.includes('fa-maxFileSize-with-backups-sync-test.log')
);
const logFiles = files.filter(file => file.includes('fa-maxFileSize-with-backups-sync-test.log'));
assert.equal(logFiles.length, 3, 'should be 3 files');
assert.same(logFiles, [
'fa-maxFileSize-with-backups-sync-test.log',
@ -136,11 +140,12 @@ test('log4js fileSyncAppender', (batch) => {
// this config defines one file appender (to ./tmp-sync-tests.log)
// and sets the log level for "tests" to WARN
log4js.configure({
appenders: { sync: {
type: 'fileSync',
filename: 'tmp-sync-tests.log',
layout: { type: 'messagePassThrough' }
}
appenders: {
sync: {
type: 'fileSync',
filename: 'tmp-sync-tests.log',
layout: { type: 'messagePassThrough' }
}
},
categories: {
default: { appenders: ['sync'], level: 'debug' },

View File

@ -76,7 +76,9 @@ const setupLogging = function (options, category, compressedLength) {
exitHandler = handler;
}
},
env: {}
removeListener: () => {},
env: {},
stderr: process.stderr
},
console: fakeConsole
}

View File

@ -30,7 +30,7 @@ test('log4js layouts', (batch) => {
assert.equal(
output,
'\x1B[31m[2010-12-05 14:18:30.045] [ERROR] cheese - \x1B[39mnonsense'
'\x1B[31m[2010-12-05T14:18:30.045] [ERROR] cheese - \x1B[39mnonsense'
);
assert.end();
});
@ -47,7 +47,7 @@ test('log4js layouts', (batch) => {
colour: 'red'
}
});
assert.equal(output, '\x1B[31m[2010-12-05 14:18:30.045] [ERROR] cheese - \x1B[39mthing 2');
assert.equal(output, '\x1B[31m[2010-12-05T14:18:30.045] [ERROR] cheese - \x1B[39mthing 2');
assert.end();
});
t.end();
@ -151,7 +151,7 @@ test('log4js layouts', (batch) => {
}
};
t.equal(layout(event), '[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test');
t.equal(layout(event), '[2010-12-05T14:18:30.045] [DEBUG] tests - this is a test');
t.test('should output a stacktrace, message if the event has an error attached', (assert) => {
let i;
@ -166,7 +166,7 @@ test('log4js layouts', (batch) => {
assert.equal(lines.length, stack.length);
assert.equal(
lines[0],
'[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test Error: Some made-up error'
'[2010-12-05T14:18:30.045] [DEBUG] tests - this is a test Error: Some made-up error'
);
for (i = 1; i < stack.length; i++) {
assert.equal(lines[i], stack[i]);
@ -175,7 +175,7 @@ test('log4js layouts', (batch) => {
assert.equal(lines.length - 1, stack.length);
assert.equal(
lines[0],
'[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test [Error: Some made-up error]'
'[2010-12-05T14:18:30.045] [DEBUG] tests - this is a test [Error: Some made-up error]'
);
for (i = 1; i < stack.length; i++) {
assert.equal(lines[i + 2], stack[i + 1]);
@ -194,7 +194,7 @@ test('log4js layouts', (batch) => {
const output = layout(event);
assert.equal(
output,
'[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test ' +
'[2010-12-05T14:18:30.045] [DEBUG] tests - this is a test ' +
"{ name: 'Cheese', message: 'Gorgonzola smells.' }"
);
assert.end();
@ -287,13 +287,13 @@ test('log4js layouts', (batch) => {
});
t.test('%d should output the date in ISO8601 format', (assert) => {
testPattern(assert, layout, event, tokens, '%d', '2010-12-05 14:18:30.045');
testPattern(assert, layout, event, tokens, '%d', '2010-12-05T14:18:30.045');
assert.end();
});
t.test('%d should allow for format specification', (assert) => {
testPattern(assert, layout, event, tokens, '%d{ISO8601_WITH_TZ_OFFSET}', '2010-12-05T14:18:30.045-0000');
testPattern(assert, layout, event, tokens, '%d{ISO8601}', '2010-12-05 14:18:30.045');
testPattern(assert, layout, event, tokens, '%d{ISO8601}', '2010-12-05T14:18:30.045');
testPattern(assert, layout, event, tokens, '%d{ABSOLUTE}', '14:18:30.045');
testPattern(assert, layout, event, tokens, '%d{DATE}', '05 12 2010 14:18:30.045');
testPattern(assert, layout, event, tokens, '%d{yy MM dd hh mm ss}', '10 12 05 14 18 30');
@ -318,7 +318,8 @@ test('log4js layouts', (batch) => {
});
t.test('should handle complicated patterns', (assert) => {
testPattern(assert, layout, event, tokens,
testPattern(
assert, layout, event, tokens,
'%m%n %c{2} at %d{ABSOLUTE} cheese %p%n',
`this is a test${EOL} of.tests at 14:18:30.045 cheese DEBUG${EOL}`
);

View File

@ -2,6 +2,7 @@
const test = require('tap').test;
const cluster = require('cluster');
const debug = require('debug')('log4js:pm2-test');
// PM2 runs everything as workers
// - no master in the cluster (PM2 acts as master itself)
@ -14,46 +15,54 @@ if (cluster.isMaster) {
cluster.fork({ NODE_APP_INSTANCE: i });
});
cluster.on('message', (worker, msg) => {
const messageHandler = (worker, msg) => {
if (worker.type || worker.topic) {
msg = worker;
}
if (msg.type === 'testing') {
debug(`Received testing message from ${msg.instance} with events ${msg.events}`);
appEvents[msg.instance] = msg.events;
}
// we have to do the re-broadcasting that the pm2-intercom module would do.
if (msg.topic === 'log4js:message') {
debug(`Received log message ${msg}`);
for (const id in cluster.workers) {
cluster.workers[id].send(msg);
}
}
});
};
cluster.on('message', messageHandler);
let count = 0;
cluster.on('exit', () => {
count += 1;
if (count === 2) {
test('PM2 Support', (batch) => {
batch.test('should not get any events when turned off', (t) => {
t.notOk(appEvents['0'].filter(e => e && e.data[0].indexOf('will not be logged') > -1).length);
t.notOk(appEvents['1'].filter(e => e && e.data[0].indexOf('will not be logged') > -1).length);
t.end();
});
// wait for any IPC messages still to come, because it seems they are slooooow.
setTimeout(() => {
test('PM2 Support', (batch) => {
batch.test('should not get any events when turned off', (t) => {
t.notOk(appEvents['0'].filter(e => e && e.data[0].indexOf('will not be logged') > -1).length);
t.notOk(appEvents['1'].filter(e => e && e.data[0].indexOf('will not be logged') > -1).length);
t.end();
});
batch.test('should get events on app instance 0', (t) => {
t.equal(appEvents['0'].length, 2);
t.equal(appEvents['0'][0].data[0], 'this should now get logged');
t.equal(appEvents['0'][1].data[0], 'this should now get logged');
t.end();
});
batch.test('should get events on app instance 0', (t) => {
t.equal(appEvents['0'].length, 2);
t.equal(appEvents['0'][0].data[0], 'this should now get logged');
t.equal(appEvents['0'][1].data[0], 'this should now get logged');
t.end();
});
batch.test('should not get events on app instance 1', (t) => {
t.equal(appEvents['1'].length, 0);
t.end();
batch.test('should not get events on app instance 1', (t) => {
t.equal(appEvents['1'].length, 0);
t.end();
});
batch.end();
cluster.removeListener('message', messageHandler);
});
batch.end();
});
}, 100);
}
});
} else {
@ -67,21 +76,30 @@ if (cluster.isMaster) {
const logger = log4js.getLogger('test');
logger.info('this is a test, but without enabling PM2 support it will not be logged');
// we have to wait a bit, so that the process.send messages get a chance to propagate
// IPC messages can take a while to get through to start with.
setTimeout(() => {
log4js.configure({
appenders: { out: { type: 'recording' } },
categories: { default: { appenders: ['out'], level: 'info' } },
pm2: true
});
const anotherLogger = log4js.getLogger('test');
anotherLogger.info('this should now get logged');
}, 500);
log4js.shutdown(() => {
log4js.configure({
appenders: { out: { type: 'recording' } },
categories: { default: { appenders: ['out'], level: 'info' } },
pm2: true
});
const anotherLogger = log4js.getLogger('test');
setTimeout(() => {
anotherLogger.info('this should now get logged');
}, 100);
// we have to wait a bit, so that the process.send messages get a chance to propagate
setTimeout(() => {
const events = recorder.replay();
process.send({ type: 'testing', instance: process.env.NODE_APP_INSTANCE, events: events });
cluster.worker.disconnect();
}, 2500);
// if we're the pm2-master we should wait for the other process to send its log messages
setTimeout(() => {
log4js.shutdown(() => {
const events = recorder.replay();
debug(`Sending test events ${events} from ${process.env.NODE_APP_INSTANCE}`);
process.send(
{ type: 'testing', instance: process.env.NODE_APP_INSTANCE, events: events },
() => { setTimeout(() => { cluster.worker.disconnect(); }, 100); }
);
});
}, 300);
});
}, 200);
}