Skip to content

Commit

Permalink
Merge pull request #311 from rollbar/verbosity
Browse files Browse the repository at this point in the history
add back verbose logging
  • Loading branch information
rokob authored Jun 15, 2017
2 parents 616642f + 6eed11a commit 07cac7a
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 37 deletions.
1 change: 1 addition & 0 deletions sdks/rollbar.js/src/browser/rollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ var defaultOptions = {
reportLevel: __DEFAULT_REPORT_LEVEL__,
uncaughtErrorLevel: __DEFAULT_UNCAUGHT_ERROR_LEVEL,
endpoint: __DEFAULT_ENDPOINT__,
verbose: false,
enabled: true
};

Expand Down
22 changes: 20 additions & 2 deletions sdks/rollbar.js/src/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ var _ = require('./utility');
* rateLimiter.shouldSend(item) -> bool
* @param api - An object which conforms to the interface
* api.postItem(payload, function(err, response))
* @param logger - An object used to log verbose messages if desired
* @param options - see Queue.prototype.configure
*/
function Queue(rateLimiter, api, options) {
function Queue(rateLimiter, api, logger, options) {
this.rateLimiter = rateLimiter;
this.api = api;
this.logger = logger;
this.options = options;
this.predicates = [];
this.pendingRequests = [];
Expand All @@ -37,7 +39,7 @@ Queue.prototype.configure = function(options) {

/*
* addPredicate - adds a predicate to the end of the list of predicates for this queue
*
*
* @param predicate - function(item, options) -> (bool|{err: Error})
* Returning true means that this predicate passes and the item is okay to go on the queue
* Returning false means do not add the item to the queue, but it is not an error
Expand Down Expand Up @@ -73,6 +75,7 @@ Queue.prototype.addItem = function(item, callback) {
callback();
return;
}
this._maybeLog(item);
this.pendingRequests.push(item);
try {
this._makeApiRequest(item, function(err, resp) {
Expand Down Expand Up @@ -212,4 +215,19 @@ Queue.prototype._dequeuePendingRequest = function(item) {
}
};

Queue.prototype._maybeLog = function(item) {
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');
if (message) {
this.logger.error(message);
return;
}
message = _.get(item, 'data.body.message.body');
if (message) {
this.logger.log(message);
}
}
};

module.exports = Queue;
2 changes: 1 addition & 1 deletion sdks/rollbar.js/src/rollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var _ = require('./utility');
function Rollbar(options, api, logger) {
this.options = _.extend(true, {}, options);
this.logger = logger;
this.queue = new Queue(Rollbar.rateLimiter, api, this.options);
this.queue = new Queue(Rollbar.rateLimiter, api, logger, this.options);
this.notifier = new Notifier(this.queue, this.options);
}

Expand Down
1 change: 1 addition & 0 deletions sdks/rollbar.js/src/server/rollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ Rollbar.defaultOptions = {
scrubFields: packageJson.defaults.server.scrubFields,
addRequestData: null,
reportLevel: packageJson.defaults.reportLevel,
verbose: false,
enabled: true
};

Expand Down
Loading

0 comments on commit 07cac7a

Please sign in to comment.