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 all commits
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 report 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 report as a string.
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