refactor tail invokation into logtail.sh

This commit is contained in:
Girish Ramakrishnan
2023-03-27 10:38:09 +02:00
parent 456da972e9
commit 603f92251e
7 changed files with 80 additions and 85 deletions

View File

@@ -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);