Skip to content

Commit

Permalink
dont wait 1hr for new data in log rotated files, allow rescan to pick…
Browse files Browse the repository at this point in the history
… up new file
  • Loading branch information
leeliu committed Jan 5, 2018
1 parent d64ac07 commit cadc2c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/file-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,11 @@ module.exports.streamFiles = function(config, logfiles, callback) {
log('Tail error: ' + file + ': ' + err);
});

tail.on('nofile', () => {
log('File does not exist, stopped tailing: ' + file + ' after ' + tail.timeout + 'ms');
tail.on('end', (err) => {
if (err) {
log('File does not exist, stopped tailing: ' + file + ' after ' + tail.timeout + 'ms');
_.pull(exports.files, file);
}
});

tail.on('rename', () => {
Expand Down
8 changes: 5 additions & 3 deletions lib/tailreadstream/tailreadstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Readable = require('stream').Readable;

const DEFAULT_WATCH_INTERVAL = 1000;
const DEFAULT_READ_INTERVAL = 1000;
const DEFAULT_READ_TIMEOUT = 3600000; // 1hr timeout
const DEFAULT_READ_TIMEOUT = 300000; // 5min timeout
const DEFAULT_TAILHEAD_SIZE = 8192; // 8kb
const DEFAULT_TAILHEAD_AGE = 60000; // 1min
const DOES_NOT_EXIST_ERROR = 'ENOENT';
Expand Down Expand Up @@ -114,7 +114,8 @@ class TailReadStream extends Readable {

if (that._hasTimedOut()) {
debug(that._filepath + ': file does not exist, timed out after ' + that._timeout + 'ms');
that.emit('nofile', err);
that.destroy();
that.emit('end', err);
return;
}

Expand Down Expand Up @@ -147,7 +148,8 @@ class TailReadStream extends Readable {

if (this._hasTimedOut()) {
debug(this._filepath + ': file no longer exists, timed out after ' + this._timeout + 'ms');
this.emit('nofile', error);
this.destroy();
this.emit('end', error);
return;
}

Expand Down

0 comments on commit cadc2c7

Please sign in to comment.