Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Roberts <vieuxtech@gmail.com>2020-03-13 19:45:39 +0300
committerSam Roberts <vieuxtech@gmail.com>2020-03-17 18:42:41 +0300
commit8cbbc70fbc835fa82c9cfffdd89a5ee323533398 (patch)
tree73986fcc9282c9f06a8eefeec2ce974de7ae92e9 /src/node_report.cc
parent9b20b5db7b829dff0bcf0383c898c7fc85924369 (diff)
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 <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'src/node_report.cc')
-rw-r--r--src/node_report.cc13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/node_report.cc b/src/node_report.cc
index c29f866f4a8..bb703594c9a 100644
--- a/src/node_report.cc
+++ b/src/node_report.cc
@@ -52,7 +52,8 @@ static void WriteNodeReport(Isolate* isolate,
const char* trigger,
const std::string& filename,
std::ostream& out,
- Local<String> stackstr);
+ Local<String> stackstr,
+ bool compact);
static void PrintVersionInformation(JSONWriter* writer);
static void PrintJavaScriptStack(JSONWriter* writer,
Isolate* isolate,
@@ -126,8 +127,9 @@ std::string TriggerNodeReport(Isolate* isolate,
std::cerr << "\nWriting Node.js report to file: " << filename;
}
+ bool compact = env != nullptr ? options->report_compact : true;
WriteNodeReport(isolate, env, message, trigger, filename, *outstream,
- stackstr);
+ stackstr, compact);
// Do not close stdout/stderr, only close files we opened.
if (outfile.is_open()) {
@@ -145,7 +147,7 @@ void GetNodeReport(Isolate* isolate,
const char* trigger,
Local<String> stackstr,
std::ostream& out) {
- WriteNodeReport(isolate, env, message, trigger, "", out, stackstr);
+ WriteNodeReport(isolate, env, message, trigger, "", out, stackstr, false);
}
// Internal function to coordinate and write the various
@@ -156,7 +158,8 @@ static void WriteNodeReport(Isolate* isolate,
const char* trigger,
const std::string& filename,
std::ostream& out,
- Local<String> stackstr) {
+ Local<String> stackstr,
+ bool compact) {
// Obtain the current time and the pid.
TIME_TYPE tm_struct;
DiagnosticFilename::LocalTime(&tm_struct);
@@ -169,7 +172,7 @@ static void WriteNodeReport(Isolate* isolate,
// File stream opened OK, now start printing the report content:
// the title and header information (event, filename, timestamp and pid)
- JSONWriter writer(out);
+ JSONWriter writer(out, compact);
writer.json_start();
writer.json_objectstart("header");
writer.json_keyvalue("reportVersion", NODE_REPORT_VERSION);