implementation for sending logs as email attachment instead of body content

This commit is contained in:
Guillaume Chauvet 2015-11-27 14:30:21 +01:00
parent e789df9884
commit fb9fee9c54

View File

@ -35,10 +35,17 @@ function sendBuffer() {
headers: {"Hostname": os.hostname()}
};
if (!config.html) {
msg.text = body;
if (true === config.attachement.enable) {
msg[config.html ? "html" : "text"] = config.attachement.message;
msg.attachments = [
{
filename: config.attachement.filename,
contentType: 'text/x-log',
content: body
}
];
} else {
msg.html = body;
msg[config.html ? "html" : "text"] = body;
}
if (config.sender) {
@ -90,12 +97,20 @@ function scheduleSend() {
*/
function smtpAppender(_config, _layout) {
config = _config;
if (!config.attachement) {
config.attachement = {};
}
config.attachement.enable = config.attachement && config.attachement.enable;
config.attachement.message = config.attachement && config.attachement.message || "See logs as attachement";
config.attachement.filename = config.attachement && config.attachement.filename || "default.log";
layout = _layout || layouts.basicLayout;
subjectLayout = layouts.messagePassThroughLayout;
sendInterval = config.sendInterval * 1000 || 0;
shutdownTimeout = ('shutdownTimeout' in config ? config.shutdownTimeout : 5) * 1000;
return function (loggingEvent) {
unsentCount++;
logEventBuffer.push(loggingEvent);
@ -118,7 +133,8 @@ function configure(_config) {
function shutdown(cb) {
if (shutdownTimeout > 0) {
setTimeout(function () {
if(sendTimer) clearTimeout(sendTimer);
if (sendTimer)
clearTimeout(sendTimer);
sendBuffer();
}, shutdownTimeout);
}