diff --git a/lib/appenders/redis.js b/lib/appenders/redis.js index 66036ef..41f4341 100644 --- a/lib/appenders/redis.js +++ b/lib/appenders/redis.js @@ -15,7 +15,7 @@ function redisAppender(config, layout) { } }); - return function (loggingEvent) { + const appender = function (loggingEvent) { const message = layout(loggingEvent); redisClient.publish(config.channel, message, (err) => { if (err) { @@ -23,6 +23,13 @@ function redisAppender(config, layout) { } }); }; + + appender.shutdown = (cb) => { + redisClient.quit(); + if (cb) cb(); + }; + + return appender; } function configure(config, layouts) { diff --git a/test/tap/redisAppender-test.js b/test/tap/redisAppender-test.js index 2c42af3..5601c53 100644 --- a/test/tap/redisAppender-test.js +++ b/test/tap/redisAppender-test.js @@ -19,7 +19,10 @@ function setupLogging(category, options) { publish: function (channel, message, callback) { fakeRedis.msgs.push({ channel: channel, message: message }); fakeRedis.publishCb = callback; - } + }, + quit: function () { + fakeRedis.quitCalled = true; + }, }; } }; @@ -46,6 +49,7 @@ function setupLogging(category, options) { return { logger: log4js.getLogger(category), + log4js: log4js, fakeRedis: fakeRedis, fakeConsole: fakeConsole }; @@ -129,5 +133,14 @@ test('log4js redisAppender', (batch) => { t.end(); }); + batch.test('shutdown', (t) => { + const setup = setupLogging('shutdown', { type: 'redis', channel: 'testing' }); + + setup.log4js.shutdown(() => { + t.ok(setup.fakeRedis.quitCalled); + t.end(); + }); + }); + batch.end(); });