module LogStashLogger::Device

Constants

DEFAULT_TYPE

Public Class Methods

build_device(opts) click to toggle source
# File lib/logstash-logger/device.rb, line 29
def self.build_device(opts)
  if parsed_uri_opts = parse_uri_config(opts)
    opts.delete(:uri)
    opts.merge!(parsed_uri_opts)
  end

  type = opts.delete(:type) || DEFAULT_TYPE

  device_klass_for(type).new(opts)
end
device_klass_for(type) click to toggle source
# File lib/logstash-logger/device.rb, line 48
def self.device_klass_for(type)
  case type.to_sym
    when :udp then UDP
    when :tcp then TCP
    when :unix then Unix
    when :file then File
    when :redis then Redis
    when :kafka then Kafka
    when :kinesis then Kinesis
    when :firehose then Firehose
    when :io then IO
    when :stdout then Stdout
    when :stderr then Stderr
    when :multi_delegator then MultiDelegator
    when :balancer then Balancer
    else fail ArgumentError, 'Invalid device type'
  end
end
new(opts) click to toggle source
# File lib/logstash-logger/device.rb, line 24
def self.new(opts)
  opts = opts.dup
  build_device(opts)
end
parse_uri_config(opts) click to toggle source
# File lib/logstash-logger/device.rb, line 40
def self.parse_uri_config(opts)
  if uri = opts[:uri]
    require 'uri'
    parsed = ::URI.parse(uri)
    {type: parsed.scheme, host: parsed.host, port: parsed.port, path: parsed.path}
  end
end