Moved Logger into separate file, added support for loading appenders outside log4js, removed 'name' from appender requirements
This commit is contained in:
@@ -16,6 +16,5 @@ function configure(config) {
|
||||
return consoleAppender(layout);
|
||||
}
|
||||
|
||||
exports.name = "console";
|
||||
exports.appender = consoleAppender;
|
||||
exports.configure = configure;
|
||||
|
||||
@@ -63,6 +63,5 @@ function configure(config, options) {
|
||||
return fileAppender(config.filename, layout, config.maxLogSize, config.backups);
|
||||
}
|
||||
|
||||
exports.name = "file";
|
||||
exports.appender = fileAppender;
|
||||
exports.configure = configure;
|
||||
|
||||
@@ -89,6 +89,5 @@ function configure(config) {
|
||||
return gelfAppender(layout, config.host, config.port, config.hostname, config.facility);
|
||||
}
|
||||
|
||||
exports.name = "gelf";
|
||||
exports.appender = gelfAppender;
|
||||
exports.configure = configure;
|
||||
|
||||
@@ -71,6 +71,5 @@ function configure(config) {
|
||||
return createAppender(config);
|
||||
}
|
||||
|
||||
exports.name = 'hookio';
|
||||
exports.appender = createAppender;
|
||||
exports.configure = configure;
|
||||
|
||||
@@ -16,6 +16,5 @@ function configure(config) {
|
||||
return logLevelFilter(config.level, appender);
|
||||
}
|
||||
|
||||
exports.name = "logLevelFilter";
|
||||
exports.appender = logLevelFilter;
|
||||
exports.configure = configure;
|
||||
|
||||
@@ -72,6 +72,5 @@ function configure(config) {
|
||||
return createAppender(config);
|
||||
}
|
||||
|
||||
exports.name = 'multiprocess';
|
||||
exports.appender = createAppender;
|
||||
exports.configure = configure;
|
||||
|
||||
+10
-11
@@ -2,15 +2,15 @@ var layouts = require("../layouts"),
|
||||
mailer = require("nodemailer");
|
||||
|
||||
/**
|
||||
* SMTP Appender. Sends logging events using SMTP protocol.
|
||||
* SMTP Appender. Sends logging events using SMTP protocol.
|
||||
* It can either send an email on each event or group several logging events gathered during specified interval.
|
||||
*
|
||||
* @param recipients comma separated list of email recipients
|
||||
* @param sender sender of all emails (defaults to SMTP user)
|
||||
* @param subject subject of all email messages (defaults to first event's message)
|
||||
* @param subject subject of all email messages (defaults to first event's message)
|
||||
* @param layout a function that takes a logevent and returns a string (defaults to basicLayout).
|
||||
* @param smtpConfig SMTP configuration for 'nodemailer'
|
||||
* @param sendInterval the time in seconds between sending attempts (defaults to 0);
|
||||
* @param sendInterval the time in seconds between sending attempts (defaults to 0);
|
||||
* all events are buffered and sent in one email during this time; if 0 than every event sends an email
|
||||
*/
|
||||
function smtpAppender(recipients, sender, subject, layout, smtpConfig, sendInterval) {
|
||||
@@ -19,20 +19,20 @@ function smtpAppender(recipients, sender, subject, layout, smtpConfig, sendInter
|
||||
subjectLayout = layouts.messagePassThroughLayout;
|
||||
mailer.SMTP = smtpConfig;
|
||||
sendInterval = sendInterval*1000 || 0;
|
||||
|
||||
|
||||
var logEventBuffer = [];
|
||||
var sendTimer;
|
||||
|
||||
|
||||
function sendBuffer() {
|
||||
if (logEventBuffer.length == 0)
|
||||
return;
|
||||
|
||||
|
||||
var firstEvent = logEventBuffer[0];
|
||||
var body = "";
|
||||
while (logEventBuffer.length > 0) {
|
||||
body += layout(logEventBuffer.shift()) + "\n";
|
||||
}
|
||||
|
||||
|
||||
var msg = {
|
||||
sender: sender,
|
||||
to: recipients,
|
||||
@@ -45,15 +45,15 @@ function smtpAppender(recipients, sender, subject, layout, smtpConfig, sendInter
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function scheduleSend() {
|
||||
if (!sendTimer)
|
||||
sendTimer = setTimeout(function() {
|
||||
sendTimer = null;
|
||||
sendTimer = null;
|
||||
sendBuffer();
|
||||
}, sendInterval);
|
||||
}
|
||||
|
||||
|
||||
return function(loggingEvent) {
|
||||
logEventBuffer.push(loggingEvent);
|
||||
if (sendInterval > 0)
|
||||
@@ -71,6 +71,5 @@ function configure(config) {
|
||||
return smtpAppender(config.recipients, config.sender, config.subject, layout, config.smtp, config.sendInterval);
|
||||
}
|
||||
|
||||
exports.name = "smtp";
|
||||
exports.appender = smtpAppender;
|
||||
exports.configure = configure;
|
||||
|
||||
Reference in New Issue
Block a user