mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-22 10:46:31 +00:00
feat(robot): Support logging arbitrary data to the console (#1212)
This adds a new command recognition for message type "log", to enable `console.log()`ing arbitrary data to the parent process console. Not sure if we'd really want this in, but it's very handy for debugging, and would keep us from writing these 3 lines every time we want to inspect something in between those processes. Change-Type: minor
This commit is contained in:
parent
4cd8776d06
commit
07b6dd247d
@ -139,6 +139,8 @@ exports.write = (image, drive, options) => {
|
|||||||
// to provide better encapsulation.
|
// to provide better encapsulation.
|
||||||
if (messageCommand === 'error') {
|
if (messageCommand === 'error') {
|
||||||
emitError(robot.recomposeErrorMessage(parsedMessage));
|
emitError(robot.recomposeErrorMessage(parsedMessage));
|
||||||
|
} else if (messageCommand === 'log') {
|
||||||
|
console.log(messageData);
|
||||||
} else {
|
} else {
|
||||||
emitter.emit(messageCommand, messageData);
|
emitter.emit(messageCommand, messageData);
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,16 @@ console.log(robot.getData(message));
|
|||||||
> }
|
> }
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Logging debug data to the console:**
|
||||||
|
|
||||||
|
*Child process:*
|
||||||
|
|
||||||
|
```js
|
||||||
|
// This will log the passed data to parent's console,
|
||||||
|
// as `console.log()`ing in the child will cause errors
|
||||||
|
robot.log({ debugging: 'things' })
|
||||||
|
```
|
||||||
|
|
||||||
The codename "robot" is inspired by [xz][xz-man], which provides a `--robot`
|
The codename "robot" is inspired by [xz][xz-man], which provides a `--robot`
|
||||||
option that makes the tool print machine-parseable output:
|
option that makes the tool print machine-parseable output:
|
||||||
|
|
||||||
|
@ -215,3 +215,17 @@ exports.printError = (error) => {
|
|||||||
exports.printMessage = (message, data) => {
|
exports.printMessage = (message, data) => {
|
||||||
console.log(exports.buildMessage(message, data));
|
console.log(exports.buildMessage(message, data));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary Log a message to the host's console
|
||||||
|
* @function
|
||||||
|
* @public
|
||||||
|
*
|
||||||
|
* @param {Object} [data] - data
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* robot.log({ example: 'data' });
|
||||||
|
*/
|
||||||
|
exports.log = (data) => {
|
||||||
|
exports.printMessage('log', data);
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user