Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace native tail with fs-tail-stream #175

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ if (program.daemonize) {
appBuilder.authorize(program.user, program.password);
}
appBuilder
.static(path.join(__dirname, 'web/assets'))
.index(path.join(__dirname, 'web/index.html'), files, filesNamespace, program.theme);
.static(path.join(__dirname, 'web', 'assets'))
.index(path.join(__dirname, 'web', 'index.html'), files, filesNamespace, program.theme);

const builder = serverBuilder();
if (doSecure) {
Expand All @@ -74,7 +74,7 @@ if (program.daemonize) {
/**
* socket.io setup
*/
const io = new SocketIO({ path: path.join(urlPath, '/socket.io') });
const io = new SocketIO({ path: `${urlPath}/socket.io` });
io.attach(server);

if (doAuthorization) {
Expand Down Expand Up @@ -105,7 +105,7 @@ if (program.daemonize) {
let presetPath;

if (!program.uiHighlightPreset) {
presetPath = path.join(__dirname, 'preset/default.json');
presetPath = path.join(__dirname, 'preset', 'default.json');
} else {
presetPath = path.resolve(untildify(program.uiHighlightPreset));
}
Expand Down
25 changes: 6 additions & 19 deletions lib/tail.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'use strict';

const events = require('events');
const childProcess = require('child_process');
const tailStream = require('fs-tail-stream');
const util = require('util');
const CBuffer = require('CBuffer');
const byline = require('byline');
Expand All @@ -23,30 +23,17 @@ function Tail(path, opts) {
this.emit('line', str);
});
} else {
let followOpt = '-F';
if (process.platform === 'openbsd') {
followOpt = '-f';
}

const tail = childProcess.spawn('tail', ['-n', options.buffer, followOpt].concat(path));

tail.stderr.on('data', (data) => {
// If there is any important error then display it in the console. Tail will keep running.
// File can be truncated over network.
if (data.toString().indexOf('file truncated') === -1) {
console.error(data.toString());
}
const tail = tailStream.createReadStream(path.join(), {
encoding: 'utf8',
start: options.buffer,
tail: true
});

byline(tail.stdout,{ keepEmptyLines: true }).on('data', (line) => {
byline(tail, { keepEmptyLines: true }).on('data', (line) => {
const str = line.toString();
this._buffer.push(str);
this.emit('line', str);
});

process.on('exit', () => {
tail.kill();
});
}
}
util.inherits(Tail, events.EventEmitter);
Expand Down
18 changes: 12 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"cookie-parser": "~1.4.3",
"daemon-fix41": "~1.1.2",
"express-session": "~1.15.6",
"fs-tail-stream": "^1.1.0",
"is-docker": "~1.1.0",
"serve-static": "~1.13.2",
"socket.io": "^2.2.0",
Expand Down