bristol-bugsnag
Version:
Bristol (https://github.com/TomFrost/Bristol) target for Bugsnag (https://bugsnag.com)
39 lines (32 loc) • 1.23 kB
JavaScript
const bugsnag = require('bugsnag');
let register = null;
/**
*
* @param {string} options.apiKey bugsnag API key (https://docs.bugsnag.com/platforms/nodejs/configuration-options/)
* @param {bugsnag.ConfigurationOptions} options.bugsnagOptions bugsnag configuration object (https://docs.bugsnag.com/platforms/nodejs/configuration-options/)
* @param {string} logSeverity The severity of the log message
* @param {Date} logDate The date of the log message
* @param {string} message The message to be pushed to bugsnag
*/
const logTarget = (targetOptions, logSeverity, logDate, logJson) => {
if (!register) {
register = bugsnag.register(targetOptions.apiKey, targetOptions.bugsnagOptions)
}
// need to translate the severity because bugsnag only accepts error, warning and info
let severityTranslated = logSeverity;
if (logSeverity === 'warn' || logSeverity === 'warning') {
severityTranslated = 'warning';
} else if (logSeverity !== 'error') {
severityTranslated = 'info';
}
const logObject = JSON.parse(logJson);
bugsnag.notify(logObject.message, {
severity: severityTranslated,
bristol: {
targetOptions,
logObject
},
logDate
});
}
module.exports = logTarget