SquadJS/log-parser/log-readers/tail.js
2020-10-05 18:56:45 +01:00

25 lines
600 B
JavaScript

import path from 'path';
import TailModule from 'tail';
export default class TailLogReader {
constructor(queueLine, options = {}) {
if (!('logDir' in options)) throw new Error(`logDir must be specified.`);
this.reader = new TailModule.Tail(path.join(options.logDir, 'SquadGame.log'), {
useWatchFile: true
});
if (typeof queueLine !== 'function')
throw new Error('queueLine argument must be specified and be a function.');
this.reader.on('line', queueLine);
}
async watch() {
this.reader.watch();
}
async unwatch() {
this.reader.unwatch();
}
}