Merge pull request #762 from florianreinhart/patch-1

Fix duplicate log messages in TCP server (fixes #761)
This commit is contained in:
Gareth Jones 2018-07-21 07:50:06 +10:00 committed by GitHub
commit 2acfce3abc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,22 +5,6 @@ const LoggingEvent = require('../LoggingEvent');
const DELIMITER = '__LOG4JS__';
let dataSoFar = '';
const send = (data) => {
if (data) {
dataSoFar += data;
if (dataSoFar.indexOf(DELIMITER)) {
const events = dataSoFar.split(DELIMITER);
if (!dataSoFar.endsWith(DELIMITER)) {
dataSoFar = events.pop();
}
events.filter(e => e.length).forEach((e) => {
clustering.send(LoggingEvent.deserialise(e));
});
}
}
};
exports.configure = (config) => {
debug('configure called with ', config);
// dummy shutdown if we're not master
@ -28,6 +12,24 @@ exports.configure = (config) => {
clustering.onlyOnMaster(() => {
const server = net.createServer((socket) => {
let dataSoFar = '';
const send = (data) => {
if (data) {
dataSoFar += data;
if (dataSoFar.indexOf(DELIMITER)) {
const events = dataSoFar.split(DELIMITER);
if (!dataSoFar.endsWith(DELIMITER)) {
dataSoFar = events.pop();
} else {
dataSoFar = '';
}
events.filter(e => e.length).forEach((e) => {
clustering.send(LoggingEvent.deserialise(e));
});
}
}
};
socket.setEncoding('utf8');
socket.on('data', send);
socket.on('end', send);