From 4ec25b4865e497b0e93974b3af6584008f279e5f Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Fri, 13 Mar 2020 09:45:39 -0700 Subject: [PATCH] src,cli: support compact (one-line) JSON reports Multi-line JSON is more human readable, but harder for log aggregators to consume, they usually require a log message per line, particularly for JSON. Compact output will be consumable by aggregators such as EFK (Elastic Search-Fluentd-Kibana), LogDNA, DataDog, etc. PR-URL: https://github.com/nodejs/node/pull/32254 Reviewed-By: Anna Henningsen Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- doc/api/cli.md | 10 ++++ doc/api/process.md | 15 ++++++ doc/api/report.md | 4 ++ doc/node.1 | 5 ++ lib/internal/process/report.js | 13 +++++- lib/internal/validators.js | 28 +++++++++++ src/node_options.cc | 4 ++ src/node_options.h | 1 + src/node_report.cc | 13 ++++-- src/node_report.h | 46 ++++++++++++++----- src/node_report_module.cc | 14 ++++++ test/common/report.js | 7 ++- test/report/test-report-config.js | 13 +++++- .../test-report-uncaught-exception-compat.js | 5 ++ 14 files changed, 158 insertions(+), 20 deletions(-) create mode 100644 test/report/test-report-uncaught-exception-compat.js diff --git a/doc/api/cli.md b/doc/api/cli.md index c050c177cfe06d..aedc223f9851fb 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -615,6 +615,15 @@ file will be created if it does not exist, and will be appended to if it does. If an error occurs while attempting to write the warning to the file, the warning will be written to stderr instead. +### `--report-compact` + + +Write reports in a compact format, single-line JSON, more easily consumable +by log processing systems than the default multi-line format designed for +human consumption. + ### `--report-directory=directory` + +* {boolean} + +Write reports in a compact format, single-line JSON, more easily consumable +by log processing systems than the default multi-line format designed for +human consumption. + +```js +console.log(`Reports are compact? ${process.report.compact}`); +``` + ### `process.report.directory`