SquadJS/core/log-parser/log-readers/tail.js

27 lines
603 B
JavaScript
Raw Normal View History

2020-05-15 12:42:39 -05:00
import path from 'path';
2020-12-10 14:46:29 -06:00
2020-05-15 12:42:39 -05:00
import TailModule from 'tail';
export default class TailLogReader {
constructor(queueLine, options = {}) {
2020-10-05 12:52:01 -05:00
if (!('logDir' in options)) throw new Error(`logDir must be specified.`);
2020-05-15 12:42:39 -05:00
2020-12-10 14:46:29 -06:00
this.reader = new TailModule.Tail(path.join(options.logDir, options.filename), {
2020-06-13 11:35:00 -05:00
useWatchFile: true
});
2020-05-15 12:42:39 -05:00
2020-10-05 12:52:01 -05:00
if (typeof queueLine !== 'function')
throw new Error('queueLine argument must be specified and be a function.');
2020-12-10 14:46:29 -06:00
2020-05-15 12:42:39 -05:00
this.reader.on('line', queueLine);
}
async watch() {
this.reader.watch();
}
async unwatch() {
this.reader.unwatch();
}
}