refactor tail invokation into logtail.sh
This commit is contained in:
16
src/apps.js
16
src/apps.js
@@ -164,7 +164,7 @@ const appstore = require('./appstore.js'),
|
||||
domains = require('./domains.js'),
|
||||
eventlog = require('./eventlog.js'),
|
||||
fs = require('fs'),
|
||||
LogStream = require('./log-stream.js'),
|
||||
logs = require('./logs.js'),
|
||||
mail = require('./mail.js'),
|
||||
manifestFormat = require('cloudron-manifestformat'),
|
||||
mounts = require('./mounts.js'),
|
||||
@@ -179,7 +179,6 @@ const appstore = require('./appstore.js'),
|
||||
services = require('./services.js'),
|
||||
settings = require('./settings.js'),
|
||||
shell = require('./shell.js'),
|
||||
spawn = require('child_process').spawn,
|
||||
storage = require('./storage.js'),
|
||||
superagent = require('superagent'),
|
||||
system = require('./system.js'),
|
||||
@@ -2025,19 +2024,10 @@ async function getLogs(app, options) {
|
||||
|
||||
const appId = app.id;
|
||||
|
||||
const lines = options.lines === -1 ? '+1' : options.lines,
|
||||
format = options.format || 'json',
|
||||
follow = options.follow;
|
||||
|
||||
assert.strictEqual(typeof format, 'string');
|
||||
|
||||
const args = [ '--lines=' + lines ];
|
||||
if (follow) args.push('--follow', '--retry', '--quiet'); // same as -F. to make it work if file doesn't exist, --quiet to not output file headers, which are no logs
|
||||
|
||||
const logPaths = await getLogPaths(app);
|
||||
const cp = spawn('/usr/bin/tail', args.concat(logPaths));
|
||||
const cp = logs.tail(logPaths, { lines: options.lines, follow: options.follow });
|
||||
|
||||
const logStream = new LogStream({ format, source: appId });
|
||||
const logStream = new logs.LogStream({ format: options.format || 'json', source: appId });
|
||||
logStream.close = cp.kill.bind(cp, 'SIGKILL'); // hook for caller. closing stream kills the child process
|
||||
|
||||
cp.stdout.pipe(logStream);
|
||||
|
||||
Reference in New Issue
Block a user