mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
Merge pull request #661 from barwin/barwin/redis-appender-shutdown
feat(redis): quit on log4js.shutdown
This commit is contained in:
commit
82d060247f
@ -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) {
|
||||
|
||||
@ -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();
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user