diff --git a/lib/errors.js b/lib/errors.js index 3361ae91..7b8da0aa 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -25,32 +25,8 @@ if (config.bugsnagCode) { emit: () => false }; - loggelf = message => { - if (typeof message === 'string') { - message = { - short_message: message - }; - } - message = message || {}; - message.facility = component; // facility is deprecated but set by the driver if not provided - message.host = hostname; - message.timestamp = Date.now() / 1000; - message._component = component; - Object.keys(message).forEach(key => { - if (!message[key]) { - delete message[key]; - } - }); - gelf.emit('gelf.log', message); - }; -} - -module.exports.notify = (...args) => { - if (bugsnag) { - bugsnag.notify(...args); - } else if (gelf) { - let err = args[0] || {}; - let extra = args[1] || {}; + loggelf = (...args) => { + let err = args.shift() || {}; let message = { short_message: component.toUpperCase() + ' [Exception] ' + (err.message || ''), @@ -66,14 +42,34 @@ module.exports.notify = (...args) => { } }); - Object.keys(extra).forEach(key => { - let vKey = '_' + key; - if (!message[vKey]) { - message[vKey] = (err[key] || '').toString().trim(); + for (let extra of args) { + Object.keys(extra || {}).forEach(key => { + let vKey = '_' + key; + if (!message[vKey]) { + message[vKey] = (err[key] || '').toString().trim(); + } + }); + } + + message.facility = component; // facility is deprecated but set by the driver if not provided + message.host = hostname; + message.timestamp = Date.now() / 1000; + message._component = component; + + Object.keys(message).forEach(key => { + if (!message[key]) { + delete message[key]; } }); + gelf.emit('gelf.log', message); + }; +} - loggelf(message); +module.exports.notify = (...args) => { + if (bugsnag) { + bugsnag.notify(...args); + } else if (gelf) { + loggelf(...args); } else { console.error(...args); } @@ -104,6 +100,8 @@ module.exports.notifyConnection = (connection, ...args) => { if (bugsnag) { bugsnag.notify(...args); + } else if (gelf) { + loggelf(...args); } else { console.error(...args); }