mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
implementation for sending logs as email attachment instead of body content
This commit is contained in:
parent
e789df9884
commit
fb9fee9c54
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user