From 5d429f2e98e782d584486f4b8b675a5a26d871b6 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. --- 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 +++++- 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 ++ 13 files changed, 130 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 d5632532f80a6f..9b45262beae077 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -592,6 +592,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`