Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions lib/winston-redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,33 @@ var Redis = exports.Redis = function (options) {
options.host = options.host || 'localhost';
options.port = options.port || 6379;


this.name = 'redis';
this.redis = options.redis || redis.createClient(options.port, options.host);
if(options.redis) {
this.redis = options.redis;
} else {
this.internalredis = true;
this.redis = redis.createClient(options.port, options.host);
}
this.json = options.json !== false;
this.length = options.length || 200;
this.container = options.container || 'winston';
this.timestamp = options.timestamp || true;
this.channel = options.pchannel || options.channel;
this.pattern = options.pattern || !!options.pchannel;
this.logstash = options.logstash === true;
this.expire = options.expire || 0;

if (options.auth) {
if (options.auth && this.internalredis) {
this.redis.auth(options.auth);
}

// Suppress errors from the Redis client
this.redis.on('error', function (err) {
self.emit('error');
});
if(this.internalredis) {
this.redis.on('error', function (err) {
self.emit('error');
});
}

if (typeof this.container !== 'function') {
var container = this.container;
Expand Down Expand Up @@ -105,6 +114,13 @@ Redis.prototype.log = function (level, msg, meta, callback) {
function(cb) {
self.redis.lpush(container, output, cb);
},
function(cb) {
if(self.expire) {
self.redis.expire(container, self.expire, cb);
} else {
cb();
}
},
function(cb) {
self.redis.ltrim(container, 0, self.length, cb);
}
Expand Down Expand Up @@ -283,9 +299,9 @@ Redis.prototype.stream = function (options) {
return stream;
};

//Close Connection to redis Server
//Close Connection to redis Server
//Winston will call close function from clear/remove to attempt to cleanly exit.
Redis.prototype.close = function(){
if (this.redis)
if (this.redis && this.internalredis)
this.redis.end();
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "winston-redis",
"description": "A fixed-length Redis transport for winston",
"version": "1.0.0",
"version": "1.0.1",
"author": "Charlie Robbins <[email protected]>",
"repository": {
"type": "git",
Expand Down