diff --git a/src/util/client/rollbarLogger.js b/src/util/client/rollbarLogger.js index 9b2463d..1c016ac 100644 --- a/src/util/client/rollbarLogger.js +++ b/src/util/client/rollbarLogger.js @@ -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 = {}) { diff --git a/src/util/common/logger.js b/src/util/common/logger.js index ecf18de..ffdaf4c 100644 --- a/src/util/common/logger.js +++ b/src/util/common/logger.js @@ -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'; @@ -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',