diff --git a/doc/cli.markdown b/doc/cli.markdown index ef66c827..5f5c8bf1 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -865,7 +865,8 @@ If an IP address is passed to this command, logs are displayed from a local mode device with that address. Note that --tail is implied when this command is provided an IP address. -Logs from a single service can be displayed with the --service flag. +Logs from a single service can be displayed with the --service flag. Just system logs +can be shown with the --system flag. Note that these flags can be used together. Examples: @@ -875,6 +876,8 @@ Examples: $ balena logs 192.168.0.31 $ balena logs 192.168.0.31 --service my-service + $ balena logs 192.168.0.31 --system + $ balena logs 192.168.0.31 --system --service my-service ### Options @@ -884,7 +887,11 @@ continuously stream output #### --service, -s <service> -Only show logs for a single service +Only show logs for a single service. This can be used in combination with --system + +#### --system, -S + +Only show system logs. This can be used in combination with --service. # Sync @@ -1417,7 +1424,9 @@ Logs will be streamed back from the device as part of the same invocation. The web dashboard can be used to switch a device to local mode: https://www.balena.io/docs/learn/develop/local-mode/ Note that local mode requires a supervisor version of at least v7.21.0. -The logs from only a single service can be shown with the --service flag. +The logs from only a single service can be shown with the --service flag, and +showing only the system logs can be achieved with --system. Note that these +flags can be used together. It is also possible to run a push to a local mode device in live mode. This will watch for changes in the source directory and perform an @@ -1447,6 +1456,8 @@ Examples: $ balena push 10.0.0.1 --source $ balena push 10.0.0.1 -s $ balena push 10.0.0.1 --service my-service + $ balena push 10.0.0.1 --system + $ balena push 10.0.0.1 --system --service my-service ### Options @@ -1487,7 +1498,12 @@ Don't tail application logs when pushing to a local mode device #### --service <service> -Only show logs from a single service. +Only show logs from a single service. This can be used in combination with --system. +Only valid when pushing to a local mode device. + +#### --system + +Only show system logs. This can be used in combination with --service. Only valid when pushing to a local mode device. # Settings diff --git a/lib/actions/logs.ts b/lib/actions/logs.ts index 8567fedf..acd5dddc 100644 --- a/lib/actions/logs.ts +++ b/lib/actions/logs.ts @@ -36,7 +36,11 @@ export const logs: CommandDefinition< { uuidOrDevice: string; }, - { tail: boolean; service: string } + { + tail: boolean; + service: string; + system: boolean; + } > = { signature: 'logs ', description: 'show device logs', @@ -51,7 +55,8 @@ export const logs: CommandDefinition< a local mode device with that address. Note that --tail is implied when this command is provided an IP address. - Logs from a single service can be displayed with the --service flag. + Logs from a single service can be displayed with the --service flag. Just system logs + can be shown with the --system flag. Note that these flags can be used together. Examples: @@ -60,7 +65,9 @@ export const logs: CommandDefinition< $ balena logs 23c73a1 --service my-service $ balena logs 192.168.0.31 - $ balena logs 192.168.0.31 --service my-service`, + $ balena logs 192.168.0.31 --service my-service + $ balena logs 192.168.0.31 --system + $ balena logs 192.168.0.31 --system --service my-service`, options: [ { signature: 'tail', @@ -70,10 +77,18 @@ export const logs: CommandDefinition< }, { signature: 'service', - description: 'Only show logs for a single service', + description: + 'Only show logs for a single service. This can be used in combination with --system', parameter: 'service', alias: 's', }, + { + signature: 'system', + alias: 'S', + boolean: true, + description: + 'Only show system logs. This can be used in combination with --service.', + }, ], permission: 'user', primary: true, @@ -96,9 +111,19 @@ export const logs: CommandDefinition< if (serviceName == null) { serviceName = 'Unknown service'; } - displayLogObject({ serviceName, ...line }, logger, options.service); + displayLogObject( + { serviceName, ...line }, + logger, + options.system || false, + options.service, + ); } else { - displayLogObject(line, logger, options.service); + displayLogObject( + line, + logger, + options.system || false, + options.service, + ); } }; @@ -117,7 +142,12 @@ export const logs: CommandDefinition< } const logStream = await deviceApi.getLogStream(); - displayDeviceLogs(logStream, logger, options.service); + displayDeviceLogs( + logStream, + logger, + options.system || false, + options.service, + ); } else { if (options.tail) { return balena.logs diff --git a/lib/actions/push.ts b/lib/actions/push.ts index 6e55c707..cf81d563 100644 --- a/lib/actions/push.ts +++ b/lib/actions/push.ts @@ -109,6 +109,7 @@ export const push: CommandDefinition< live: boolean; detached: boolean; service: string; + system: boolean; } > = { signature: 'push ', @@ -129,7 +130,9 @@ export const push: CommandDefinition< The web dashboard can be used to switch a device to local mode: https://www.balena.io/docs/learn/develop/local-mode/ Note that local mode requires a supervisor version of at least v7.21.0. - The logs from only a single service can be shown with the --service flag. + The logs from only a single service can be shown with the --service flag, and + showing only the system logs can be achieved with --system. Note that these + flags can be used together. It is also possible to run a push to a local mode device in live mode. This will watch for changes in the source directory and perform an @@ -147,6 +150,8 @@ export const push: CommandDefinition< $ balena push 10.0.0.1 --source $ balena push 10.0.0.1 -s $ balena push 10.0.0.1 --service my-service + $ balena push 10.0.0.1 --system + $ balena push 10.0.0.1 --system --service my-service `, options: [ { @@ -204,10 +209,17 @@ export const push: CommandDefinition< { signature: 'service', description: stripIndent` - Only show logs from a single service. + Only show logs from a single service. This can be used in combination with --system. Only valid when pushing to a local mode device.`, parameter: 'service', }, + { + signature: 'system', + description: stripIndent` + Only show system logs. This can be used in combination with --service. + Only valid when pushing to a local mode device.`, + boolean: true, + }, ], async action(params, options, done) { const sdk = (await import('balena-sdk')).fromSharedOptions(); @@ -260,6 +272,11 @@ export const push: CommandDefinition< 'The --service flag is only valid when pushing to a local mode device.', ); } + if (options.system) { + exitWithExpectedError( + 'The --system flag is only valid when pushing to a local mode device.', + ); + } const app = appOrDevice; await exitIfNotLoggedIn(); @@ -301,6 +318,7 @@ export const push: CommandDefinition< live: options.live || false, detached: options.detached || false, service: options.service, + system: options.system || false, }), ) .catch(BuildError, e => { diff --git a/lib/utils/device/deploy.ts b/lib/utils/device/deploy.ts index 41ecfaab..9585a448 100644 --- a/lib/utils/device/deploy.ts +++ b/lib/utils/device/deploy.ts @@ -49,6 +49,7 @@ export interface DeviceDeployOptions { live: boolean; detached: boolean; service?: string; + system: boolean; } async function checkSource(source: string): Promise { @@ -176,10 +177,10 @@ export async function deployToDevice(opts: DeviceDeployOptions): Promise { globalLogger.logLivepush('Watching for file changes...'); await Promise.all([ livepush.init(), - displayDeviceLogs(logStream, globalLogger, opts.service), + displayDeviceLogs(logStream, globalLogger, opts.system, opts.service), ]); } else { - await displayDeviceLogs(logStream, globalLogger, opts.service); + await displayDeviceLogs(logStream, globalLogger, opts.system, opts.service); } } diff --git a/lib/utils/device/logs.ts b/lib/utils/device/logs.ts index 544be5b1..8225391d 100644 --- a/lib/utils/device/logs.ts +++ b/lib/utils/device/logs.ts @@ -28,17 +28,20 @@ interface BuildLog { * objects * @param logger A Logger instance which the logs will be * displayed through + * @param system Only show system (and potentially the + * filterService) logs * @param filterService Filter the logs so that only logs * from a single service will be displayed */ export function displayDeviceLogs( logs: Readable, logger: Logger, + system: boolean, filterService?: string, ): Bluebird { return new Bluebird((resolve, reject) => { logs.on('data', log => { - displayLogLine(log, logger, filterService); + displayLogLine(log, logger, system, filterService); }); logs.on('error', reject); @@ -57,11 +60,12 @@ export function displayBuildLog(log: BuildLog, logger: Logger): void { function displayLogLine( log: string | Buffer, logger: Logger, + system: boolean, filterService?: string, ): void { try { const obj: Log = JSON.parse(log.toString()); - displayLogObject(obj, logger, filterService); + displayLogObject(obj, logger, system, filterService); } catch (e) { logger.logDebug(`Dropping device log due to failed parsing: ${e}`); } @@ -70,6 +74,7 @@ function displayLogLine( export function displayLogObject( obj: T, logger: Logger, + system: boolean, filterService?: string, ): void { let toPrint: string; @@ -80,13 +85,18 @@ export function displayLogObject( } if (obj.serviceName != null) { - if (filterService && obj.serviceName !== filterService) { + if (filterService) { + if (obj.serviceName !== filterService) { + return; + } + } else if (system) { return; } + const colourFn = getServiceColourFn(obj.serviceName); toPrint += ` ${colourFn(`[${obj.serviceName}]`)}`; - } else if (filterService != null) { + } else if (filterService != null && !system) { // We have a system log here but we are filtering based // on a service, so drop this too return;