Skip to content

Commit

Permalink
Handle client rollbar init more gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Nason committed Oct 18, 2016
1 parent 738823a commit fc81634
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/util/client/rollbarLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,23 @@ import omit from 'lodash/omit';
import { bunyanLevelToRollbarLevelName } from '../common/rollbar';

export default function RollbarLogger({ token, environment, codeVersion }) {
// TODO test for rollbar in head via `global.Rollbar`,
// if present update config, else init
if (global.Rollbar && global.Rollbar.options.accessToken && global.Rollbar.accessToken !== 'undefined') {
// Rollbar is loaded globally (ie, the quick-start snippet has been pasted into the document's head)
} else {
// Init Rollbar here
Rollbar.init({
accessToken: token,
captureUncaught: true,
captureUnhandledRejections: true,
payload: {
environment,
javascipt: {
code_version: codeVersion,
source_map_enabled: true
}
}
});
}
}

RollbarLogger.prototype.write = function (data = {}) {
Expand Down
4 changes: 2 additions & 2 deletions src/util/common/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @module we-js-logger/util/logger
* @description Base logger class, used for both node and client loggers
*
* Uses (bunyan)[https://github.com/trentm/node-bunyan/] under the hood, which has a few quirks
* Uses [bunyan](https://github.com/trentm/node-bunyan/) under the hood, which has a few quirks
*/
import bunyan from 'bunyan';

Expand All @@ -18,7 +18,7 @@ export default class Logger {
* @param {Object} options.serializers - bunyan serializer configuration
* @param {String} options.logentriesToken - Logentries API token
* @param {String} options.rollbarToken - Rollbar token
* @returns {Object} a configured bunyan instance
* @returns {Object} a configured bunyan instance
*/
constructor({
name = 'WeWork',
Expand Down

0 comments on commit fc81634

Please sign in to comment.