Sha256: 28f52512fa3dd8eaead53e04f2240fab9655d045a40b7a2b2c4b9ab60d2fa3e1

Contents?: true

Size: 615 Bytes

Versions: 2

Compression:

Stored size: 615 Bytes

Contents

require 'redis'
require 'redis/namespace'

class Woodchuck::Output::Redis < Woodchuck::Output
  attr_accessor :url, :host, :port, :db, :namespace
  
  def initialize(log_level)
    super(log_level)
    @type = :redis
    @url = Addressable::URI.parse(ENV['REDIS_URL'] || 'redis://localhost:6379/9')
    @namespace = ENV['REDIS_NAMESPACE'] || 'logstash:woodchuck'
  end
  
  def redis
    client = ::Redis.new(:url => url)
    ::Redis::Namespace.new(namespace, :redis => client)
  end
  
  def handle(event)
    redis.lpush("events", event.to_json)
    @logger.info "Logging event to Redis", event.to_hash
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
woodchuck-json-event-0.0.2 lib/woodchuck/output/redis.rb
woodchuck-json-event-0.0.1 lib/woodchuck/output/redis.rb