Module: LogStashLogger::Device

Defined in:
lib/logstash-logger/device.rb,
lib/logstash-logger/device/io.rb,
lib/logstash-logger/device/tcp.rb,
lib/logstash-logger/device/udp.rb,
lib/logstash-logger/device/base.rb,
lib/logstash-logger/device/file.rb,
lib/logstash-logger/device/http.rb,
lib/logstash-logger/device/unix.rb,
lib/logstash-logger/device/kafka.rb,
lib/logstash-logger/device/redis.rb,
lib/logstash-logger/device/socket.rb,
lib/logstash-logger/device/stderr.rb,
lib/logstash-logger/device/stdout.rb,
lib/logstash-logger/device/kinesis.rb,
lib/logstash-logger/device/balancer.rb,
lib/logstash-logger/device/firehose.rb,
lib/logstash-logger/device/aws_stream.rb,
lib/logstash-logger/device/connectable.rb,
lib/logstash-logger/device/multi_delegator.rb

Defined Under Namespace

Classes: AwsStream, Balancer, Base, Connectable, File, Firehose, HTTP, IO, Kafka, Kinesis, MultiDelegator, Redis, Socket, Stderr, Stdout, TCP, UDP, Unix

Constant Summary collapse

DEFAULT_TYPE =
:udp

Class Method Summary collapse

Class Method Details

.build_device(opts) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/logstash-logger/device.rb', line 30

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

.cast_uri_value(key, value) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/logstash-logger/device.rb', line 60

def self.cast_uri_value(key, value)
  case key
  when 'buffer_max_items'
    value.to_i
  else
    value
  end
end

.device_klass_for(type) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/logstash-logger/device.rb', line 69

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
    when :http then HTTP
    else fail ArgumentError, 'Invalid device type'
  end
end

.new(opts) ⇒ Object



25
26
27
28
# File 'lib/logstash-logger/device.rb', line 25

def self.new(opts)
  opts = opts.dup
  build_device(opts)
end

.parse_uri_config(opts) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/logstash-logger/device.rb', line 41

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}
      .merge(parse_uri_query(parsed.query))
  end
end

.parse_uri_query(query) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/logstash-logger/device.rb', line 50

def self.parse_uri_query(query)
  return {} unless query && !query.empty?
  ::URI.decode_www_form(query).each_with_object({}) do |(key, value), acc|
    next unless key
    key = key.to_s.strip
    next if key.empty?
    acc[key.to_sym] = cast_uri_value(key, value)
  end
end