8000 Update redis.js · LikeABossProgrammer/log4js-node@4b6fce1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4b6fce1

Browse files
authored
Update redis.js
1 parent 20ad278 commit 4b6fce1

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/appenders/redis.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,32 @@ const layouts = require('../layouts');
44
const redis = require('redis');
55
const util = require('util');
66

7-
function redisAppender(host = '127.0.0.1', port = 6379, pass = '', channel = 'log', layout = layouts.messagePassThroughLayout) {
8-
const redisClient = redis.createClient(port, host, { auth_pass: pass });
7+
let layout;
8+
9+
function redisAppender(config, layout = layouts.messagePassThroughLayout) {
10+
const redisClient = redis.createClient(config.port, config.host, { auth_pass: config.pass });
911
redisClient.on('error', (err) => {
1012
if (err) {
11-
console.error('log4js.redisAppender - %s:%p Error: %s', host, port, util.inspect(err));
13+
console.error('log4js.redisAppender - %s:%p Error: %s', config.host, config.port, util.inspect(err));
1214
}
1315
});
1416
return function (loggingEvent) {
1517
const message = layout(loggingEvent);
16-
redisClient.publish(channel, message, (err) => {
18+
redisClient.publish(config.channel, message, (err) => {
1719
if (err) {
18-
console.error('log4js.redisAppender - %s:%p Error: %s', host, port, util.inspect(err));
20+
console.error('log4js.redisAppender - %s:%p Error: %s', config.host, config.port, util.inspect(err));
1921
}
2022
});
2123
};
2224
}
2325

2426
function configure(config) {
25-
return redisAppender(config.host, config.port, config.pass, config.channel, layouts.layout(config.layout.type, config.layout));
27+
if (config.layout) {
28+
layout = layouts.layout(config.layout.type, config.layout);
29+
}
30+
31+
return redisAppender(config, layout);
2632
}
2733

28-
exports.appender = redisAppender;
29-
exports.configure = configure;
34+
module.exports.appender = redisAppender;
35+
module.exports.configure = configure;

0 commit comments

Comments
 (0)
0