Fix line param parsing

lines is a positive integer or -1 to disable line limiting. The
default value is 10 if no argument is given.

Fixes #604
This commit is contained in:
Girish Ramakrishnan
2019-01-08 12:10:53 -08:00
parent 1affb2517a
commit 810f5e7409
9 changed files with 48 additions and 37 deletions

View File

@@ -369,24 +369,25 @@ function getServiceLogs(serviceName, options, callback) {
assert(options && typeof options === 'object');
assert.strictEqual(typeof callback, 'function');
assert.strictEqual(typeof options.lines, 'number');
assert.strictEqual(typeof options.format, 'string');
assert.strictEqual(typeof options.follow, 'boolean');
if (!KNOWN_SERVICES[serviceName]) return callback(new AddonsError(AddonsError.NOT_FOUND));
debug(`Getting logs for ${serviceName}`);
var lines = options.lines || 100,
var lines = options.lines,
format = options.format || 'json',
follow = !!options.follow;
follow = options.follow;
assert.strictEqual(typeof lines, 'number');
assert.strictEqual(typeof format, 'string');
var cmd;
var args = [ '--lines=' + lines ];
let cmd, args = [];
// docker and unbound use journald
if (serviceName === 'docker' || serviceName === 'unbound') {
cmd = 'journalctl';
args.push('--lines=' + (lines === -1 ? 'all' : lines));
args.push(`--unit=${serviceName}`);
args.push('--no-pager');
args.push('--output=short-iso');
@@ -395,6 +396,7 @@ function getServiceLogs(serviceName, options, callback) {
} else {
cmd = '/usr/bin/tail';
args.push('--lines=' + (lines === -1 ? '+1' : 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
args.push(path.join(paths.LOG_DIR, serviceName, 'app.log'));
}