| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5adaf10 commit b5b7bf5
13 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -592,6 +592,15 @@ file will be created if it does not exist, and will be appended to if it does. | |||
| 592 | 592 | If an error occurs while attempting to write the warning to the file, the | |
| 593 | 593 | warning will be written to stderr instead. | |
| 594 | 594 | ||
| 595 | + ### `--report-compact` | ||
| 596 | + <!-- YAML | ||
| 597 | + added: REPLACEME | ||
| 598 | + --> | ||
| 599 | + | ||
| 600 | + Write reports in a compact format, single-line JSON, more easily consumable | ||
| 601 | + by log processing systems than the default multi-line format designed for | ||
| 602 | + human consumption. | ||
| 603 | + | ||
| 595 | 604 | ### `--report-directory=directory` | |
| 596 | 605 | <!-- YAML | |
| 597 | 606 | added: v11.8.0 | |
@@ -1136,6 +1145,7 @@ Node.js options that are allowed are: | |||
| 1136 | 1145 | * `--preserve-symlinks` | |
| 1137 | 1146 | * `--prof-process` | |
| 1138 | 1147 | * `--redirect-warnings` | |
| 1148 | + * `--report-compact` | ||
| 1139 | 1149 | * `--report-directory` | |
| 1140 | 1150 | * `--report-filename` | |
| 1141 | 1151 | * `--report-on-fatalerror` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1767,6 +1767,21 @@ changes: | |||
| 1767 | 1767 | reports for the current process. Additional documentation is available in the | |
| 1768 | 1768 | [report documentation][]. | |
| 1769 | 1769 | ||
| 1770 | + ### `process.report.compact` | ||
| 1771 | + <!-- YAML | ||
| 1772 | + added: REPLACEME | ||
| 1773 | + --> | ||
| 1774 | + | ||
| 1775 | + * {boolean} | ||
| 1776 | + | ||
| 1777 | + Write reports in a compact format, single-line JSON, more easily consumable | ||
| 1778 | + by log processing systems than the default multi-line format designed for | ||
| 1779 | + human consumption. | ||
| 1780 | + | ||
| 1781 | + ```js | ||
| 1782 | + console.log(`Reports are compact? ${process.report.compact}`); | ||
| 1783 | + ``` | ||
| 1784 | + | ||
| 1770 | 1785 | ### `process.report.directory` | |
| 1771 | 1786 | <!-- YAML | |
| 1772 | 1787 | added: v11.12.0 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -419,6 +419,10 @@ that leads to termination of the application. Useful to inspect various | |||
| 419 | 419 | diagnostic data elements such as heap, stack, event loop state, resource | |
| 420 | 420 | consumption etc. to reason about the fatal error. | |
| 421 | 421 | ||
| 422 | + * `--report-compact` Write reports in a compact format, single-line JSON, more | ||
| 423 | + easily consumable by log processing systems than the default multi-line format | ||
| 424 | + designed for human consumption. | ||
| 425 | + | ||
| 422 | 426 | * `--report-directory` Location at which the report will be | |
| 423 | 427 | generated. | |
| 424 | 428 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -281,6 +281,11 @@ Write process warnings to the given | |||
| 281 | 281 | .Ar file | |
| 282 | 282 | instead of printing to stderr. | |
| 283 | 283 | . | |
| 284 | + .It Fl -report-compact | ||
| 285 | + Write | ||
| 286 | + .Sy diagnostic reports | ||
| 287 | + in a compact format, single-line JSON. | ||
| 288 | + . | ||
| 284 | 289 | .It Fl -report-directory | |
| 285 | 290 | Location at which the | |
| 286 | 291 | .Sy diagnostic report | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,11 @@ const { | |||
| 3 | 3 | ERR_INVALID_ARG_TYPE, | |
| 4 | 4 | ERR_SYNTHETIC | |
| 5 | 5 | } = require('internal/errors').codes; | |
| 6 | - const { validateSignalName, validateString } = require('internal/validators'); | ||
| 6 | + const { | ||
| 7 | + validateSignalName, | ||
| 8 | + validateString, | ||
| 9 | + validateBoolean, | ||
| 10 | + } = require('internal/validators'); | ||
| 7 | 11 | const nr = internalBinding('report'); | |
| 8 | 12 | const { | |
| 9 | 13 | JSONParse, | |
@@ -45,6 +49,13 @@ const report = { | |||
| 45 | 49 | validateString(name, 'filename'); | |
| 46 | 50 | nr.setFilename(name); | |
| 47 | 51 | }, | |
| 52 | + get compact() { | ||
| 53 | + return nr.getCompact(); | ||
| 54 | + }, | ||
| 55 | + set compact(b) { | ||
| 56 | + validateBoolean(b, 'compact'); | ||
| 57 | + nr.setCompact(b); | ||
| 58 | + }, | ||
| 48 | 59 | get signal() { | |
| 49 | 60 | return nr.getSignal(); | |
| 50 | 61 | }, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -577,6 +577,10 @@ PerIsolateOptionsParser::PerIsolateOptionsParser( | |||
| 577 | 577 | "generate diagnostic report on uncaught exceptions", | |
| 578 | 578 | &PerIsolateOptions::report_uncaught_exception, | |
| 579 | 579 | kAllowedInEnvironment); | |
| 580 | + AddOption("--report-compact", | ||
| 581 | + "output compact single-line JSON", | ||
| 582 | + &PerIsolateOptions::report_compact, | ||
| 583 | + kAllowedInEnvironment); | ||
| 580 | 584 | AddOption("--report-on-signal", | |
| 581 | 585 | "generate diagnostic report upon receiving signals", | |
| 582 | 586 | &PerIsolateOptions::report_on_signal, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -187,6 +187,7 @@ class PerIsolateOptions : public Options { | |||
| 187 | 187 | bool report_uncaught_exception = false; | |
| 188 | 188 | bool report_on_signal = false; | |
| 189 | 189 | bool report_on_fatalerror = false; | |
| 190 | + bool report_compact = false; | ||
| 190 | 191 | std::string report_signal = "SIGUSR2"; | |
| 191 | 192 | std::string report_filename; | |
| 192 | 193 | std::string report_directory; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,7 +52,8 @@ static void WriteNodeReport(Isolate* isolate, | |||
| 52 | 52 | const char* trigger, | |
| 53 | 53 | const std::string& filename, | |
| 54 | 54 | std::ostream& out, | |
| 55 | - Local<String> stackstr); | ||
| 55 | + Local<String> stackstr, | ||
| 56 | + bool compact); | ||
| 56 | 57 | static void PrintVersionInformation(JSONWriter* writer); | |
| 57 | 58 | static void PrintJavaScriptStack(JSONWriter* writer, | |
| 58 | 59 | Isolate* isolate, | |
@@ -126,8 +127,9 @@ std::string TriggerNodeReport(Isolate* isolate, | |||
| 126 | 127 | std::cerr << "\nWriting Node.js report to file: " << filename; | |
| 127 | 128 | } | |
| 128 | 129 | ||
| 130 | + bool compact = env != nullptr ? options->report_compact : true; | ||
| 129 | 131 | WriteNodeReport(isolate, env, message, trigger, filename, *outstream, | |
| 130 | - stackstr); | ||
| 132 | + stackstr, compact); | ||
| 131 | 133 | ||
| 132 | 134 | // Do not close stdout/stderr, only close files we opened. | |
| 133 | 135 | if (outfile.is_open()) { | |
@@ -145,7 +147,7 @@ void GetNodeReport(Isolate* isolate, | |||
| 145 | 147 | const char* trigger, | |
| 146 | 148 | Local<String> stackstr, | |
| 147 | 149 | std::ostream& out) { | |
| 148 | - WriteNodeReport(isolate, env, message, trigger, "", out, stackstr); | ||
| 150 | + WriteNodeReport(isolate, env, message, trigger, "", out, stackstr, false); | ||
| 149 | 151 | } | |
| 150 | 152 | ||
| 151 | 153 | // Internal function to coordinate and write the various | |
@@ -156,7 +158,8 @@ static void WriteNodeReport(Isolate* isolate, | |||
| 156 | 158 | const char* trigger, | |
| 157 | 159 | const std::string& filename, | |
| 158 | 160 | std::ostream& out, | |
| 159 | - Local<String> stackstr) { | ||
| 161 | + Local<String> stackstr, | ||
| 162 | + bool compact) { | ||
| 160 | 163 | // Obtain the current time and the pid. | |
| 161 | 164 | TIME_TYPE tm_struct; | |
| 162 | 165 | DiagnosticFilename::LocalTime(&tm_struct); | |
@@ -169,7 +172,7 @@ static void WriteNodeReport(Isolate* isolate, | |||
| 169 | 172 | // File stream opened OK, now start printing the report content: | |
| 170 | 173 | // the title and header information (event, filename, timestamp and pid) | |
| 171 | 174 | ||
| 172 | - JSONWriter writer(out); | ||
| 175 | + JSONWriter writer(out, compact); | ||
| 173 | 176 | writer.json_start(); | |
| 174 | 177 | writer.json_objectstart("header"); | |
| 175 | 178 | writer.json_keyvalue("reportVersion", NODE_REPORT_VERSION); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,25 +65,37 @@ extern double prog_start_time; | |||
| 65 | 65 | // JSON compiler definitions. | |
| 66 | 66 | class JSONWriter { | |
| 67 | 67 | public: | |
| 68 | - explicit JSONWriter(std::ostream& out) : out_(out) {} | ||
| 68 | + JSONWriter(std::ostream& out, bool compact) | ||
| 69 | + : out_(out), compact_(compact) {} | ||
| 69 | 70 | ||
| 71 | + private: | ||
| 70 | 72 | inline void indent() { indent_ += 2; } | |
| 71 | 73 | inline void deindent() { indent_ -= 2; } | |
| 72 | 74 | inline void advance() { | |
| 75 | + if (compact_) return; | ||
| 73 | 76 | for (int i = 0; i < indent_; i++) out_ << ' '; | |
| 74 | 77 | } | |
| 78 | + inline void write_one_space() { | ||
| 79 | + if (compact_) return; | ||
| 80 | + out_ << ' '; | ||
| 81 | + } | ||
| 82 | + inline void write_new_line() { | ||
| 83 | + if (compact_) return; | ||
| 84 | + out_ << '\n'; | ||
| 85 | + } | ||
| 75 | 86 | ||
| 87 | + public: | ||
| 76 | 88 | inline void json_start() { | |
| 77 | 89 | if (state_ == kAfterValue) out_ << ','; | |
| 78 | - out_ << '\n'; | ||
| 90 | + write_new_line(); | ||
| 79 | 91 | advance(); | |
| 80 | 92 | out_ << '{'; | |
| 81 | 93 | indent(); | |
| 82 | 94 | state_ = kObjectStart; | |
| 83 | 95 | } | |
| 84 | 96 | ||
| 85 | 97 | inline void json_end() { | |
| 86 | - out_ << '\n'; | ||
| 98 | + write_new_line(); | ||
| 87 | 99 | deindent(); | |
| 88 | 100 | advance(); | |
| 89 | 101 | out_ << '}'; | |
@@ -92,34 +104,42 @@ class JSONWriter { | |||
| 92 | 104 | template <typename T> | |
| 93 | 105 | inline void json_objectstart(T key) { | |
| 94 | 106 | if (state_ == kAfterValue) out_ << ','; | |
| 95 | - out_ << '\n'; | ||
| 107 | + write_new_line(); | ||
| 96 | 108 | advance(); | |
| 97 | 109 | write_string(key); | |
| 98 | - out_ << ": {"; | ||
| 110 | + out_ << ':'; | ||
| 111 | + write_one_space(); | ||
| 112 | + out_ << '{'; | ||
| 99 | 113 | indent(); | |
| 100 | 114 | state_ = kObjectStart; | |
| 101 | 115 | } | |
| 102 | 116 | ||
| 103 | 117 | template <typename T> | |
| 104 | 118 | inline void json_arraystart(T key) { | |
| 105 | 119 | if (state_ == kAfterValue) out_ << ','; | |
| 106 | - out_ << '\n'; | ||
| 120 | + write_new_line(); | ||
| 107 | 121 | advance(); | |
| 108 | 122 | write_string(key); | |
| 109 | - out_ << ": ["; | ||
| 123 | + out_ << ':'; | ||
| 124 | + write_one_space(); | ||
| 125 | + out_ << '['; | ||
| 110 | 126 | indent(); | |
| 111 | 127 | state_ = kObjectStart; | |
| 112 | 128 | } | |
| 113 | 129 | inline void json_objectend() { | |
| 114 | - out_ << '\n'; | ||
| 130 | + write_new_line(); | ||
| 115 | 131 | deindent(); | |
| 116 | 132 | advance(); | |
| 117 | 133 | out_ << '}'; | |
| 134 | + if (indent_ == 0) { | ||
| 135 | + // Top-level object is complete, so end the line. | ||
| 136 | + out_ << '\n'; | ||
| 137 | + } | ||
| 118 | 138 | state_ = kAfterValue; | |
| 119 | 139 | } | |
| 120 | 140 | ||
| 121 | 141 | inline void json_arrayend() { | |
| 122 | - out_ << '\n'; | ||
| 142 | + write_new_line(); | ||
| 123 | 143 | deindent(); | |
| 124 | 144 | advance(); | |
| 125 | 145 | out_ << ']'; | |
@@ -128,18 +148,19 @@ class JSONWriter { | |||
| 128 | 148 | template <typename T, typename U> | |
| 129 | 149 | inline void json_keyvalue(const T& key, const U& value) { | |
| 130 | 150 | if (state_ == kAfterValue) out_ << ','; | |
| 131 | - out_ << '\n'; | ||
| 151 | + write_new_line(); | ||
| 132 | 152 | advance(); | |
| 133 | 153 | write_string(key); | |
| 134 | - out_ << ": "; | ||
| 154 | + out_ << ':'; | ||
| 155 | + write_one_space(); | ||
| 135 | 156 | write_value(value); | |
| 136 | 157 | state_ = kAfterValue; | |
| 137 | 158 | } | |
| 138 | 159 | ||
| 139 | 160 | template <typename U> | |
| 140 | 161 | inline void json_element(const U& value) { | |
| 141 | 162 | if (state_ == kAfterValue) out_ << ','; | |
| 142 | - out_ << '\n'; | ||
| 163 | + write_new_line(); | ||
| 143 | 164 | advance(); | |
| 144 | 165 | write_value(value); | |
| 145 | 166 | state_ = kAfterValue; | |
@@ -177,6 +198,7 @@ class JSONWriter { | |||
| 177 | 198 | ||
| 178 | 199 | enum JSONState { kObjectStart, kAfterValue }; | |
| 179 | 200 | std::ostream& out_; | |
| 201 | + bool compact_; | ||
| 180 | 202 | int indent_ = 0; | |
| 181 | 203 | int state_ = kObjectStart; | |
| 182 | 204 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,6 +68,18 @@ void GetReport(const FunctionCallbackInfo<Value>& info) { | |||
| 68 | 68 | .ToLocalChecked()); | |
| 69 | 69 | } | |
| 70 | 70 | ||
| 71 | + static void GetCompact(const FunctionCallbackInfo<Value>& info) { | ||
| 72 | + Environment* env = Environment::GetCurrent(info); | ||
| 73 | + info.GetReturnValue().Set(env->isolate_data()->options()->report_compact); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + static void SetCompact(const FunctionCallbackInfo<Value>& info) { | ||
| 77 | + Environment* env = Environment::GetCurrent(info); | ||
| 78 | + Isolate* isolate = env->isolate(); | ||
| 79 | + bool compact = info[0]->ToBoolean(isolate)->Value(); | ||
| 80 | + env->isolate_data()->options()->report_compact = compact; | ||
| 81 | + } | ||
| 82 | + | ||
| 71 | 83 | static void GetDirectory(const FunctionCallbackInfo<Value>& info) { | |
| 72 | 84 | Environment* env = Environment::GetCurrent(info); | |
| 73 | 85 | std::string directory = env->isolate_data()->options()->report_directory; | |
@@ -161,6 +173,8 @@ static void Initialize(Local<Object> exports, | |||
| 161 | 173 | ||
| 162 | 174 | env->SetMethod(exports, "writeReport", WriteReport); | |
| 163 | 175 | env->SetMethod(exports, "getReport", GetReport); | |
| 176 | + env->SetMethod(exports, "getCompact", GetCompact); | ||
| 177 | + env->SetMethod(exports, "setCompact", SetCompact); | ||
| 164 | 178 | env->SetMethod(exports, "getDirectory", GetDirectory); | |
| 165 | 179 | env->SetMethod(exports, "setDirectory", SetDirectory); | |
| 166 | 180 | env->SetMethod(exports, "getFilename", GetFilename); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments