added shutdownTimeout option

master
hasegawa-jun 10 years ago
parent adfad9ad20
commit 4dfe14a0c2

@ -2,7 +2,8 @@
var layouts = require("../layouts")
, mailer = require("nodemailer")
, os = require('os')
, unsentCount = 0;
, unsentCount = 0
, shutdownTimeout;
/**
* SMTP Appender. Sends logging events using SMTP protocol.
@ -12,6 +13,7 @@ var layouts = require("../layouts")
* @param config appender configuration data
* config.sendInterval time between log emails (in seconds), if 0
* then every event sends an email
* config.shutdownTimeout time to give up remaining emails (in seconds; defaults to 5).
* @param layout a function that takes a logevent and returns a string (defaults to basicLayout).
*/
function smtpAppender(config, layout) {
@ -22,6 +24,8 @@ function smtpAppender(config, layout) {
var logEventBuffer = [];
var sendTimer;
shutdownTimeout = ('shutdownTimeout' in config ? config.shutdownTimeout : 5) * 1000;
function sendBuffer() {
if (logEventBuffer.length > 0) {
@ -87,8 +91,11 @@ function configure(config) {
}
function shutdown(cb) {
async.until(function() {
return unsentCount === 0;
if (shutdownTimeout > 0) {
setTimeout(function() { unsentCount = 0; }, shutdownTimeout);
}
async.whilst(function() {
return unsentCount > 0;
}, function(done) {
setTimeout(done, 100);
}, cb);

Loading…
Cancel
Save