Skip to content

Commit

Permalink
fixed bad cutoff logic
Browse files Browse the repository at this point in the history
  • Loading branch information
leeliu committed Apr 1, 2016
1 parent 158f08b commit 116818b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/file-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ module.exports.streamDir = function (dir, socket) {

debug('tailing: ' + file);
tail.on('line', function (line) {
linebuffer.addMessage(JSON.stringify({ e: 'l', t: Date.now(), l: line, f: file }));
linebuffer.addMessage({ e: 'l', t: Date.now(), l: line, f: file });
});
tail.on('error', function (err) {
log('Tail error: ' + file + ': ' + err);
Expand Down
11 changes: 5 additions & 6 deletions lib/linebuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ var dccount = 0;

module.exports.addMessage = function (message) {
if (buf.length > config.BUF_LIMIT) {
debug('buffer limit exceeded');
debug('buffer limit exceeded ' + buf.length);
return;
}

if (message.length > 32000) {
message = message.substring(0, 32000) + ' (cut off, too long...)';
if (message.l.length > 32000) {
debug('super long line ' + message.l.length);
message.l = message.l.substring(0, 32000) + ' (cut off, too long...)';
}

buf.push(message);
buf.push(JSON.stringify(message));

// flush immediately if limit reached
if (buf.length === config.FLUSH_LIMIT) {
Expand All @@ -41,8 +42,6 @@ module.exports.flush = function () {

for (var i = 0; i < sendbuf.length; i++) {
debug('sending data: ' + sendbuf[i].length);
if (!sendbuf[i] || sendbuf[i].length === 0) continue;

socket.send(sendbuf[i]);
}
sendbuf = null;
Expand Down
2 changes: 1 addition & 1 deletion lib/windows-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports.streamEventLog = function (provider, socket) {
// logObjects is an Array
debug('Number of log objects found: ' + logObjects.length);
logObjects.forEach(logObject => {
linebuffer.addMessage(JSON.stringify({ e: 'l', t: Date.now(), l: logObject.message, f: logObject.providerName }));
linebuffer.addMessage({ e: 'l', t: Date.now(), l: logObject.message, f: logObject.providerName });
});
});

Expand Down

0 comments on commit 116818b

Please sign in to comment.