From 48bccd34dba569a574110a045cc264201d26f4a1 Mon Sep 17 00:00:00 2001 From: Cameron Diver Date: Wed, 21 Aug 2019 15:01:18 +0100 Subject: [PATCH] Add journald format flag Change-type: minor Signed-off-by: Cameron Diver --- docs/API.md | 7 ++++++- src/device-api/v2.ts | 3 ++- src/lib/journald.ts | 5 +++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/API.md b/docs/API.md index 8e950556..b49dfae6 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1185,7 +1185,7 @@ Unsuccessful response: Added in supervisor version v10.2.0 Retrieve a stream to the journald logs on device. This is -equivalent to running `journalctl -o export`. Options +equivalent to running `journalctl --no-pager`. Options supported are: ##### all: boolean @@ -1203,6 +1203,11 @@ Show the most recent `count` events, equivalent to Show journal logs from `unit` only, equivalent to `journalctl --unit=`. +##### format +The format which will be streamed from journalctl, formats +are described here: +https://www.freedesktop.org/software/systemd/man/journalctl.html#-o + Fields should be provided via POST body in JSON format. From an application container (with systemd installed): diff --git a/src/device-api/v2.ts b/src/device-api/v2.ts index 1cfe8069..08ffe4e6 100644 --- a/src/device-api/v2.ts +++ b/src/device-api/v2.ts @@ -539,8 +539,9 @@ export function createV2Api(router: Router, applications: ApplicationManager) { const follow = checkTruthy(req.body.follow) || false; const count = checkInt(req.body.count, { positive: true }) || undefined; const unit = req.body.unit; + const format = req.body.format || 'short'; - const journald = spawnJournalctl({ all, follow, count, unit }); + const journald = spawnJournalctl({ all, follow, count, unit, format }); res.status(200); journald.stdout.pipe(res); res.on('close', () => { diff --git a/src/lib/journald.ts b/src/lib/journald.ts index d7fe9195..22516614 100644 --- a/src/lib/journald.ts +++ b/src/lib/journald.ts @@ -8,13 +8,12 @@ export function spawnJournalctl(opts: { follow: boolean; count?: number; unit?: string; + format: string; }): ChildProcess { const args = [ // The directory we want to run the chroot from constants.rootMountPoint, 'journalctl', - '-o', - 'export', ]; if (opts.all) { args.push('-a'); @@ -30,6 +29,8 @@ export function spawnJournalctl(opts: { args.push('-n'); args.push(opts.count.toString()); } + args.push('-o'); + args.push(opts.format); log.debug('Spawning journald with: chroot ', args.join(' '));