Skip to content

Commit

Permalink
Merge pull request #332 from rollbar/fix-verbose-logging
Browse files Browse the repository at this point in the history
Fix #331 Verbose logging was using the wrong key structure
  • Loading branch information
rokob authored Jul 11, 2017
2 parents 66d3828 + e8bfec4 commit c08ebbe
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
12 changes: 12 additions & 0 deletions sdks/rollbar.js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,18 @@ If you're using the [Passport](http://passportjs.org/) authentication library, t

Note: in Rollbar, the `id` is used to uniquely identify a person; `email` and `username` are supplemental and will be overwritten whenever a new value is received for an existing `id`. The `id` is a string up to 40 characters long.

## Verbose Option

If you would like to see what is being sent to Rollbar in your console, use the
`verbose` option. Set `verbose: true` in your configuration, and we will output certain information
via the [debug](https://www.npmjs.com/package/debug) package. This package uses the `DEBUG`
environment variable to configure what to output. We use the namespace `Rollbar` for our
log messages, so for example, to see everything you need to do something like this:

```
DEBUG=Rollbar:* node app.js
```

## Upgrading from node_rollbar

The upgrade path from `node_rollbar` version 0.6.4 to version 2.0.0 of this library is not
Expand Down
5 changes: 3 additions & 2 deletions sdks/rollbar.js/src/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ Notifier.prototype.log = function(item, callback) {
return callback(new Error('Rollbar is not enabled'));
}

var originalError = item.err;
this._applyTransforms(item, function(err, i) {
if (err) {
return callback(err, null);
}
this.queue.addItem(i, callback);
this.queue.addItem(i, callback, originalError);
}.bind(this));
};

Expand Down Expand Up @@ -108,7 +109,7 @@ Notifier.prototype._applyTransforms = function(item, callback) {

transforms[transformIndex](i, options, cb);
};

cb(null, item);
};

Expand Down
14 changes: 8 additions & 6 deletions sdks/rollbar.js/src/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ Queue.prototype.addPredicate = function(predicate) {
* in the case of a success, otherwise response will be null and error will have a value. If both
* error and response are null then the item was stopped by a predicate which did not consider this
* to be an error condition, but nonetheless did not send the item to the API.
* @param originalError - The original error before any transformations that is to be logged if any
*/
Queue.prototype.addItem = function(item, callback) {
Queue.prototype.addItem = function(item, callback, originalError) {
if (!callback || !_.isFunction(callback)) {
callback = function() { return; };
}
Expand All @@ -75,7 +76,7 @@ Queue.prototype.addItem = function(item, callback) {
callback();
return;
}
this._maybeLog(item);
this._maybeLog(item, originalError);
this.pendingRequests.push(item);
try {
this._makeApiRequest(item, function(err, resp) {
Expand Down Expand Up @@ -215,15 +216,16 @@ Queue.prototype._dequeuePendingRequest = function(item) {
}
};

Queue.prototype._maybeLog = function(item) {
Queue.prototype._maybeLog = function(data, originalError) {
if (this.logger && this.options.verbose) {
var message = _.get(item, 'data.body.trace.exception.message');
message = message || _.get(item, 'data.body.trace_chain.0.exception.message');
var message = originalError;
message = message || _.get(data, 'body.trace.exception.message');
message = message || _.get(data, 'body.trace_chain.0.exception.message');
if (message) {
this.logger.error(message);
return;
}
message = _.get(item, 'data.body.message.body');
message = _.get(data, 'body.message.body');
if (message) {
this.logger.log(message);
}
Expand Down
6 changes: 3 additions & 3 deletions sdks/rollbar.js/test/queue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('addItem', function() {
var options = {verbose: true};
var queue = new Queue(rateLimiter, api, logger, options);

var item = {data: {body: {trace: {exception: {message: 'hello'}}}}};
var item = {body: {trace: {exception: {message: 'hello'}}}};
var serverResponse = {success: true};

rateLimiter.handler = function(i) {
Expand All @@ -198,7 +198,7 @@ describe('addItem', function() {
var options = {verbose: true};
var queue = new Queue(rateLimiter, api, logger, options);

var item = {data: {body: {message: {body: 'hello'}}}};
var item = {body: {message: {body: 'hello'}}};
var serverResponse = {success: true};

rateLimiter.handler = function(i) {
Expand All @@ -222,7 +222,7 @@ describe('addItem', function() {
var options = {verbose: false};
var queue = new Queue(rateLimiter, api, logger, options);

var item = {data: {body: {message: {body: 'hello'}}}};
var item = {body: {message: {body: 'hello'}}};
var serverResponse = {success: true};

rateLimiter.handler = function(i) {
Expand Down

0 comments on commit c08ebbe

Please sign in to comment.