--json or --yaml output cannot be isolated from logging output
Tools (like Website Evidence Collector BATCH) may rely on WEC outputting JSON (along the lines of inspection.json) to stdout -- and nothing but1 that JSON payload. It's easier to pipe in just JSON than to pre-process the received data to remove logging noise around it.
Latest WEC uses winston/logger as means for console output; progress logging as well as JSON/YAML payload is output using logger.‹level_method›(), the latter at info level.23 I understand all that output goes to stderr. Requested payload should go to stdout, though.4
The suggestion is, to use a simple console.log("%s", json_dump) or console.log("%s", yaml_dump) instead, respectively, to unconditionally output inspection payload when requested by using --json or --yaml flags.
(A second issue is addressed in the following patch: sometimes (not yet understood when) save‹FMT›ToFile() is called with an empty object prior to being called with an non-empty inspection data object. In composition that leads to invalid JSON ("{}\n{ "...": "..", ...}"). Hence the guard against empty objects being output in the patch below – treating the symptom rather than the problem.)
diff --git a/src/reporter/reporter.ts b/src/reporter/reporter.ts
index 8e292aa..4e97912 100644
--- a/src/reporter/reporter.ts
+++ b/src/reporter/reporter.ts
@@ -243,8 +243,8 @@ export class Reporter {
this.saveFile(filename, json_dump);
- if (this.options.printJsonToConsole) {
- this.logger.info(json_dump);
+ if (this.options.printJsonToConsole && Object.keys(data).length > 0) {
+ console.log("%s", json_dump);
}
}
@@ -271,8 +271,8 @@ export class Reporter {
this.saveFile(filename, yaml_dump);
- if (this.options.printYamlToConsole) {
- this.logger.info(yaml_dump);
+ if (this.options.printYamlToConsole && Object.keys(data).length > 0) {
+ console.log("%s", yaml_dump);
}
}