diff --git a/lib/appenders/smtp.js b/lib/appenders/smtp.js index 557bc71..203e94f 100644 --- a/lib/appenders/smtp.js +++ b/lib/appenders/smtp.js @@ -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); }