Module: LogStasher::Device

Included in:
Redis, Syslog, UDP
Defined in:
lib/logstasher/device.rb,
lib/logstasher/device/udp.rb,
lib/logstasher/device/redis.rb,
lib/logstasher/device/syslog.rb

Defined Under Namespace

Classes: Redis, Syslog, UDP

Class Method Summary collapse

Class Method Details

.factory(config) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/logstasher/device.rb', line 3

def self.factory(config)
  config = stringify_keys(config)
  type   = config.delete('type') or fail ArgumentError, 'No "type" given'

  case type
  when 'redis', :redis then
    require 'logstasher/device/redis'
    ::LogStasher::Device::Redis.new(config)
  when "syslog", :syslog then
    require 'logstasher/device/syslog'
    ::LogStasher::Device::Syslog.new(config)
  when "udp", :udp then
    require 'logstasher/device/udp'
    ::LogStasher::Device::UDP.new(config)
  when "stdout", :stdout then
    $stdout
  else
    fail ArgumentError, "Unknown type: #{type}"
  end
end

.stringify_keys(hash) ⇒ Object



24
25
26
27
28
29
# File 'lib/logstasher/device.rb', line 24

def stringify_keys(hash)
  hash.inject({}) do |stringified_hash, (key, value)|
    stringified_hash[key.to_s] = value
    stringified_hash
  end
end