diff --git a/config/default.toml b/config/default.toml index 596c319b..cd145bd0 100644 --- a/config/default.toml +++ b/config/default.toml @@ -22,10 +22,6 @@ maxForwards=2000 # If usernames are not email addresses then use this domain as hostname part #emailDomain="mydomain.info" -# Bugsnag API key -# If set then reports errors to Bugsnag -bugsnagCode="" - [dbs] # @include "dbs.toml" diff --git a/lib/errors.js b/lib/errors.js index 0aa84544..e50c702a 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -6,97 +6,87 @@ const Gelf = require('gelf'); const os = require('os'); const util = require('util'); -let bugsnag; let loggelf; let component; let hostname; module.exports.gelf = {}; -if (config.bugsnagCode) { - bugsnag = require('bugsnag'); - bugsnag.register(config.bugsnagCode); -} else { - let gelfconf = (config && config.log && config.log.gelf) || {}; +let gelfconf = (config && config.log && config.log.gelf) || {}; - component = gelfconf.component || 'wildduck'; - hostname = gelfconf.hostname || os.hostname(); +component = gelfconf.component || 'wildduck'; +hostname = gelfconf.hostname || os.hostname(); - module.exports.gelf.handler = gelfconf.enabled - ? new Gelf(gelfconf.options) - : { - emit: (channel, message) => console.error(util.inspect(message, false, 3)) - }; +module.exports.gelf.handler = gelfconf.enabled + ? new Gelf(gelfconf.options) + : { + emit: (channel, message) => console.error(util.inspect(message, false, 3)) + }; - loggelf = (...args) => { - let err = args.shift() || {}; - if (err.code === 'ECONNRESET') { - // just ignore - return; - } +loggelf = (...args) => { + let err = args.shift() || {}; + if (err.code === 'ECONNRESET') { + // just ignore + return; + } - let message = { - short_message: component.toUpperCase() + ' [Exception] ' + (err.message || ''), - full_message: err.stack, - _exception: 'yes', - _error: err.message - }; - - let limitLength = val => { - let str = (val || '').toString().trim(); - if (str.length > 256) { - str = str.substr(0, 256) + '…'; - } - return str; - }; - - Object.keys(err).forEach(key => { - let vKey = '_' + key; - if (!message[vKey] && typeof err[key] !== 'object') { - message[vKey] = limitLength(err[key]); - } - }); - - for (let extra of args) { - Object.keys(extra || {}).forEach(key => { - let vKey = '_' + key; - if (!message[vKey] && typeof extra[key] !== 'object') { - message[vKey] = limitLength(extra[key]); - } - }); - } - - 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]; - } - }); - - try { - module.exports.gelf.handler.emit('gelf.log', message); - } catch (err) { - // might fail on non-JSONizable input - try { - console.error(err); - console.error(util.inspect(message, false, 3)); - } catch (err) { - //ignore - } - } + let message = { + short_message: component.toUpperCase() + ' [Exception] ' + (err.message || ''), + full_message: err.stack, + _exception: 'yes', + _error: err.message }; -} + + let limitLength = val => { + let str = (val || '').toString().trim(); + if (str.length > 256) { + str = str.substr(0, 256) + '…'; + } + return str; + }; + + Object.keys(err).forEach(key => { + let vKey = '_' + key; + if (!message[vKey] && typeof err[key] !== 'object') { + message[vKey] = limitLength(err[key]); + } + }); + + for (let extra of args) { + Object.keys(extra || {}).forEach(key => { + let vKey = '_' + key; + if (!message[vKey] && typeof extra[key] !== 'object') { + message[vKey] = limitLength(extra[key]); + } + }); + } + + 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]; + } + }); + + try { + module.exports.gelf.handler.emit('gelf.log', message); + } catch (err) { + // might fail on non-JSONizable input + try { + console.error(err); + console.error(util.inspect(message, false, 3)); + } catch (err) { + //ignore + } + } +}; module.exports.notify = (...args) => { - if (bugsnag) { - bugsnag.notify(...args); - } else { - loggelf(...args); - } + loggelf(...args); }; module.exports.notifyConnection = (connection, ...args) => { @@ -120,30 +110,7 @@ module.exports.notifyConnection = (connection, ...args) => { }); args[1] = metaData; - - if (bugsnag) { - bugsnag.notify(...args); - } else { - loggelf(...args); - } -}; - -module.exports.intercept = (...args) => { - if (bugsnag) { - return bugsnag.intercept(...args); - } - let cb; - if (args.length) { - cb = args[args.length - 1]; - if (typeof cb === 'function') { - args[args.length - 1] = function(...returnArgs) { - if (returnArgs.length > 1 && returnArgs[0]) { - console.error(returnArgs[0]); - } - return cb(...returnArgs); - }; - } - } + loggelf(...args); }; module.exports.setGelf = gelf => { diff --git a/package.json b/package.json index 8dd6cb72..d6e12c25 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "description": "IMAP/POP3 server built with Node.js and MongoDB", "main": "server.js", "scripts": { - "toc": "markdown-toc -i docs/api.md", "test": "mongo --eval 'db.dropDatabase()' wildduck-test && redis-cli -n 13 flushdb && NODE_ENV=test grunt", "apidoc": "apidoc -i lib/api/ -o docs/", "show": "NODE_CONFIG_ONLY=true node server.js" @@ -31,7 +30,6 @@ "grunt-wait": "0.3.0", "icedfrisby": "1.5.0", "mailparser": "2.4.3", - "markdown-toc": "1.2.0", "mocha": "5.2.0", "request": "2.88.0" }, @@ -40,7 +38,6 @@ "accesscontrol": "2.2.1", "base32.js": "0.1.0", "bcryptjs": "2.4.3", - "bugsnag": "2.4.3", "gelf": "2.0.1", "generate-password": "1.4.1", "he": "1.2.0",