2020-10-05 12:52:01 -05:00
|
|
|
import path from 'path';
|
|
|
|
import FTPTail from 'ftp-tail';
|
|
|
|
|
|
|
|
export default class TailLogReader {
|
|
|
|
constructor(queueLine, options = {}) {
|
|
|
|
for (const option of ['host', 'user', 'password', 'logDir'])
|
|
|
|
if (!(option in options)) throw new Error(`${option} must be specified.`);
|
|
|
|
|
|
|
|
this.reader = new FTPTail({
|
|
|
|
host: options.host,
|
|
|
|
port: options.port || 21,
|
|
|
|
user: options.user,
|
|
|
|
password: options.password,
|
|
|
|
secure: options.secure || false,
|
|
|
|
timeout: options.timeout || 2000,
|
|
|
|
encoding: 'utf8',
|
|
|
|
verbose: options.verbose,
|
|
|
|
|
2020-12-10 14:46:29 -06:00
|
|
|
path: path.join(options.logDir, options.filename),
|
2020-10-05 12:52:01 -05:00
|
|
|
|
|
|
|
fetchInterval: options.fetchInterval || 0,
|
2020-10-22 12:18:44 -05:00
|
|
|
maxTempFileSize: options.maxTempFileSize || 5 * 1000 * 1000, // 5 MB
|
|
|
|
|
|
|
|
useListForSize: options.useListForSize
|
2020-10-05 12:52:01 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
if (typeof queueLine !== 'function')
|
|
|
|
throw new Error('queueLine argument must be specified and be a function.');
|
|
|
|
this.reader.on('line', queueLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
async watch() {
|
|
|
|
await this.reader.watch();
|
|
|
|
}
|
|
|
|
|
|
|
|
async unwatch() {
|
|
|
|
await this.reader.unwatch();
|
|
|
|
}
|
|
|
|
}
|