Sha256: 617db87c6a675ca31087e4dac54bc81ecb08e68aad38a0565c5f25b9dbde6434

Contents?: true

Size: 909 Bytes

Versions: 5

Compression:

Stored size: 909 Bytes

Contents

module LogStasher
  module Device
    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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
md-logstasher-1.8.0 lib/logstasher/device.rb
md-logstasher-1.7.0 lib/logstasher/device.rb
md-logstasher-1.6.0 lib/logstasher/device.rb
md-logstasher-1.5.0 lib/logstasher/device.rb
md-logstasher-1.4.1 lib/logstasher/device.rb