Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ application.
var nodereport = require('node-report');
nodereport.triggerReport();
```
The content of a NodeReport can also be returned as a JavaScript string via an
API call from a JavaScript application.

```js
var nodereport = require('nodereport');
var report_str = nodereport.getReport();
console.log(report_str);
```
The API can be used without adding the automatic exception and fatal error
hooks and the signal handler, as follows:

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const options = process.env.NODEREPORT_EVENTS || 'exception+fatalerror+signal+ap
api.setEvents(options);

exports.triggerReport = api.triggerReport;
exports.getReport = api.getReport;
exports.setEvents = api.setEvents;
exports.setCoreDump = api.setCoreDump;
exports.setSignal = api.setSignal;
Expand Down
17 changes: 17 additions & 0 deletions src/module.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "node_report.h"
#include <nan.h>
#include <sstream>

namespace nodereport {

Expand Down Expand Up @@ -67,6 +68,20 @@ NAN_METHOD(TriggerReport) {
}
}

/*******************************************************************************
* External JavaScript API for returning a report
*
******************************************************************************/
NAN_METHOD(GetReport) {
Nan::HandleScope scope;
v8::Isolate* isolate = info.GetIsolate();
std::ostringstream out;

GetNodeReport(isolate, kJavaScript, "JavaScript API", __func__, out);
// Return value is the contents of a NodeReport as a string.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Since this is a newly introduced line, replace "NodeReport" with "report" so it doesn't need to change again for #52.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If #52 is merged first I'll need to make changes here, if this one is merged first then the renaming one will need updates. I'll make sure it gets done at that point with everything else rather than do just one of the (many) changes I'll probably need to make ahead of time.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#52 has now been merged, please can you rebase and update accordingly?

info.GetReturnValue().Set(Nan::New(out.str()).ToLocalChecked());
}

/*******************************************************************************
* External JavaScript APIs for node-report configuration
*
Expand Down Expand Up @@ -392,6 +407,8 @@ void Initialize(v8::Local<v8::Object> exports) {

exports->Set(Nan::New("triggerReport").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(TriggerReport)->GetFunction());
exports->Set(Nan::New("getReport").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(GetReport)->GetFunction());
exports->Set(Nan::New("setEvents").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(SetEvents)->GetFunction());
exports->Set(Nan::New("setSignal").ToLocalChecked(),
Expand Down
Loading