8000 Merge pull request #661 from barwin/barwin/redis-appender-shutdown · xyz-data/log4js-node@82d0602 · GitHub
[go: up one dir, main page]

Skip to content

Commit 82d0602

Browse files
authored
Merge pull request log4js-node#661 from barwin/barwin/redis-appender-shutdown
feat(redis): quit on log4js.shutdown
2 parents 05ad768 + 2a28437 commit 82d0602

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/appenders/redis.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,21 @@ function redisAppender(config, layout) {
1515
}
1616
});
1717

18-
return function (loggingEvent) {
18+
const appender = function (loggingEvent) {
1919
const message = layout(loggingEvent);
2020
redisClient.publish(config.channel, message, (err) => {
2121
if (err) {
2222
console.error(`log4js.redisAppender - ${host}:${port} Error: ${util.inspect(err)}`);
2323
}
2424
});
2525
};
26+
27+
appender.shutdown = (cb) => {
28+
redisClient.quit();
29+
if (cb) cb();
30+
};
31+
32+
return appender;
2633
}
2734

2835
function configure(config, layouts) {

test/tap/redisAppender-test.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ function setupLogging(category, options) {
1919
publish: function (channel, message, callback) {
2020
fakeRedis.msgs.push({ channel: channel, message: message });
2121
fakeRedis.publishCb = callback;
22-
}
22+
},
23+
quit: function () {
24+
fakeRedis.quitCalled = true;
25+
},
2326
};
2427
}
2528
};
@@ -46,6 +49,7 @@ function setupLogging(category, options) {
4649

4750
return {
4851
logger: log4js.getLogger(category),
52+
log4js: log4js,
4953
fakeRedis: fakeRedis,
5054
fakeConsole: fakeConsole
5155
};
@@ -129,5 +133,14 @@ test('log4js redisAppender', (batch) => {
129133
t.end();
130134
});
131135

136+
batch.test('shutdown', (t) => {
137+
const setup = setupLogging('shutdown', { type: 'redis', channel: 'testing' });
138+
139+
setup.log4js.shutdown(() => {
140+
t.ok(setup.fakeRedis.quitCalled);
141+
t.end();
142+
});
143+
});
144+
132145
batch.end();
133146
});

0 commit comments

Comments
 (0)
0