logstash-redis

Uber simple Logstash logging using Redis

logstash-redis

Uber simple Logstash logging using Redis

Node version: 0.8.0 required

Build status:

Installation

npm install logstash-redis

Usage

The simple way:

var logstashRedis = require('logstash-redis');
 
var logger = logstashRedis.createLogger('127.0.0.1', 6379, 'key');
 
logger.log({ a: 1234, b: 'hello' });
 
logger.close();

Using a base object for each log:

var logstashRedis = require('logstash-redis');
 
var baseObject = {
  type: 'someValue',
  env: "prod-1234"
};
 
var logger = logstashRedis.createLogger('127.0.0.1', 6379, 'key', baseObject);
 
logger.log({ a: 1234, b: 'hello' });
 
logger.close();

Using a base function for each log:

var logstashRedis = require('logstash-redis');
 
var baseFunction = function(){
  return  {
    type: 'someValue',
    meta: {
      timestamp: new Date().toISOString(),
      host: require('os').hostname()
    }
  };
};
 
var logger = logstashRedis.createLogger('127.0.0.1', 6379, 'key', baseFunction);
 
logger.log({ a: 1234, b: 'hello' });
 
logger.close();

API

Initiate a Redis connection. When the base parameter is specified, it is used as a base for each log object. It can be an object or a function.

Logs some data asynchronously. Data is a valid javascript object. If a base object or function had been provided during initialisation, data will extend it.

Subscribes a function fn to the error event. When the error will happen fn will be executed with some error details as parameter.

Cleanly closes the Redis connection (all replies will be parsed).

The NullLogger

It does exactly nothing. Good for testing.

var logstashRedis = require('logstash-redis');
 
var logger = logstashRedis.createNullLogger();
 
logger.log({ a: 1234, b: 'hello' });
// does nothing 
 
logger.close();
// does nothing 

Tests

npm test

License

MIT

Contributors