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

25 lines
600 B
JavaScript
Raw Normal View History

2020-05-15 12:42:39 -05:00
import path from 'path';
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-06-13 11:35:00 -05:00
this.reader = new TailModule.Tail(path.join(options.logDir, 'SquadGame.log'), {
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-05-15 12:42:39 -05:00
this.reader.on('line', queueLine);
}
async watch() {
this.reader.watch();
}
async unwatch() {
this.reader.unwatch();
}
}