This commit is contained in:
Andris Reinman 2018-10-18 11:20:29 +03:00
parent d25e0180b7
commit 9c0be98c1c

View file

@ -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 => {
for (let extra of args) {
Object.keys(extra || {}).forEach(key => {
let vKey = '_' + key;
if (!message[vKey]) {
message[vKey] = (err[key] || '').toString().trim();
}
});
}
loggelf(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) {
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);
}