mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-10-09 05:18:19 +08:00
remove bugsnag
This commit is contained in:
parent
ebab1f7b22
commit
c3f2b8f3d3
3 changed files with 69 additions and 109 deletions
|
@ -22,10 +22,6 @@ maxForwards=2000
|
||||||
# If usernames are not email addresses then use this domain as hostname part
|
# If usernames are not email addresses then use this domain as hostname part
|
||||||
#emailDomain="mydomain.info"
|
#emailDomain="mydomain.info"
|
||||||
|
|
||||||
# Bugsnag API key
|
|
||||||
# If set then reports errors to Bugsnag
|
|
||||||
bugsnagCode=""
|
|
||||||
|
|
||||||
[dbs]
|
[dbs]
|
||||||
# @include "dbs.toml"
|
# @include "dbs.toml"
|
||||||
|
|
||||||
|
|
171
lib/errors.js
171
lib/errors.js
|
@ -6,97 +6,87 @@ const Gelf = require('gelf');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
|
||||||
let bugsnag;
|
|
||||||
let loggelf;
|
let loggelf;
|
||||||
let component;
|
let component;
|
||||||
let hostname;
|
let hostname;
|
||||||
|
|
||||||
module.exports.gelf = {};
|
module.exports.gelf = {};
|
||||||
|
|
||||||
if (config.bugsnagCode) {
|
let gelfconf = (config && config.log && config.log.gelf) || {};
|
||||||
bugsnag = require('bugsnag');
|
|
||||||
bugsnag.register(config.bugsnagCode);
|
|
||||||
} else {
|
|
||||||
let gelfconf = (config && config.log && config.log.gelf) || {};
|
|
||||||
|
|
||||||
component = gelfconf.component || 'wildduck';
|
component = gelfconf.component || 'wildduck';
|
||||||
hostname = gelfconf.hostname || os.hostname();
|
hostname = gelfconf.hostname || os.hostname();
|
||||||
|
|
||||||
module.exports.gelf.handler = gelfconf.enabled
|
module.exports.gelf.handler = gelfconf.enabled
|
||||||
? new Gelf(gelfconf.options)
|
? new Gelf(gelfconf.options)
|
||||||
: {
|
: {
|
||||||
emit: (channel, message) => console.error(util.inspect(message, false, 3))
|
emit: (channel, message) => console.error(util.inspect(message, false, 3))
|
||||||
};
|
};
|
||||||
|
|
||||||
loggelf = (...args) => {
|
loggelf = (...args) => {
|
||||||
let err = args.shift() || {};
|
let err = args.shift() || {};
|
||||||
if (err.code === 'ECONNRESET') {
|
if (err.code === 'ECONNRESET') {
|
||||||
// just ignore
|
// just ignore
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let message = {
|
let message = {
|
||||||
short_message: component.toUpperCase() + ' [Exception] ' + (err.message || ''),
|
short_message: component.toUpperCase() + ' [Exception] ' + (err.message || ''),
|
||||||
full_message: err.stack,
|
full_message: err.stack,
|
||||||
_exception: 'yes',
|
_exception: 'yes',
|
||||||
_error: err.message
|
_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 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) => {
|
module.exports.notify = (...args) => {
|
||||||
if (bugsnag) {
|
loggelf(...args);
|
||||||
bugsnag.notify(...args);
|
|
||||||
} else {
|
|
||||||
loggelf(...args);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.notifyConnection = (connection, ...args) => {
|
module.exports.notifyConnection = (connection, ...args) => {
|
||||||
|
@ -120,30 +110,7 @@ module.exports.notifyConnection = (connection, ...args) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
args[1] = metaData;
|
args[1] = metaData;
|
||||||
|
loggelf(...args);
|
||||||
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);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.setGelf = gelf => {
|
module.exports.setGelf = gelf => {
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
"description": "IMAP/POP3 server built with Node.js and MongoDB",
|
"description": "IMAP/POP3 server built with Node.js and MongoDB",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"toc": "markdown-toc -i docs/api.md",
|
|
||||||
"test": "mongo --eval 'db.dropDatabase()' wildduck-test && redis-cli -n 13 flushdb && NODE_ENV=test grunt",
|
"test": "mongo --eval 'db.dropDatabase()' wildduck-test && redis-cli -n 13 flushdb && NODE_ENV=test grunt",
|
||||||
"apidoc": "apidoc -i lib/api/ -o docs/",
|
"apidoc": "apidoc -i lib/api/ -o docs/",
|
||||||
"show": "NODE_CONFIG_ONLY=true node server.js"
|
"show": "NODE_CONFIG_ONLY=true node server.js"
|
||||||
|
@ -31,7 +30,6 @@
|
||||||
"grunt-wait": "0.3.0",
|
"grunt-wait": "0.3.0",
|
||||||
"icedfrisby": "1.5.0",
|
"icedfrisby": "1.5.0",
|
||||||
"mailparser": "2.4.3",
|
"mailparser": "2.4.3",
|
||||||
"markdown-toc": "1.2.0",
|
|
||||||
"mocha": "5.2.0",
|
"mocha": "5.2.0",
|
||||||
"request": "2.88.0"
|
"request": "2.88.0"
|
||||||
},
|
},
|
||||||
|
@ -40,7 +38,6 @@
|
||||||
"accesscontrol": "2.2.1",
|
"accesscontrol": "2.2.1",
|
||||||
"base32.js": "0.1.0",
|
"base32.js": "0.1.0",
|
||||||
"bcryptjs": "2.4.3",
|
"bcryptjs": "2.4.3",
|
||||||
"bugsnag": "2.4.3",
|
|
||||||
"gelf": "2.0.1",
|
"gelf": "2.0.1",
|
||||||
"generate-password": "1.4.1",
|
"generate-password": "1.4.1",
|
||||||
"he": "1.2.0",
|
"he": "1.2.0",
|
||||||
|
|
Loading…
Add table
Reference in a new issue