Class: LogStashLogger::Device::TCP

Inherits:
Socket show all
Defined in:
lib/logstash-logger/device/tcp.rb

Constant Summary

Constants inherited from Socket

Socket::DEFAULT_HOST

Instance Attribute Summary collapse

Attributes inherited from Socket

#host, #port

Attributes inherited from Connectable

#buffer_logger

Attributes inherited from Base

#error_logger, #sync

Instance Method Summary collapse

Methods inherited from Socket

#unrecoverable_error?

Methods inherited from Connectable

#close, #connected?, #flush, #on_full_buffer_receive, #reconnect, #reset, #to_io, #with_connection, #write, #write_batch, #write_one

Methods included from Buffer

#buffer_flush, #buffer_full?, #buffer_initialize, #buffer_receive, #reset_buffer

Methods inherited from Base

#close, #close!, #flush, #reset, #to_io, #unrecoverable_error?, #write, #write_batch, #write_one

Constructor Details

#initialize(opts) ⇒ TCP

Returns a new instance of TCP.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/logstash-logger/device/tcp.rb', line 8

def initialize(opts)
  super

  @ssl_certificate = opts[:ssl_certificate]
  @ssl_context = opts[:ssl_context]
  @use_ssl = !!(@ssl_certificate || opts[:ssl_context])
  @use_ssl = opts[:ssl_enable] if opts.has_key? :ssl_enable
  if opts.has_key?(:use_ssl)
    @use_ssl = opts[:use_ssl]
    warn "[LogStashLogger] The use_ssl option is deprecated. Use ssl_enable instead."
  end
  @verify_hostname = opts.fetch(:verify_hostname, true)
end

Instance Attribute Details

#ssl_certificateObject (readonly)

Returns the value of attribute ssl_certificate.



6
7
8
# File 'lib/logstash-logger/device/tcp.rb', line 6

def ssl_certificate
  @ssl_certificate
end

Instance Method Details

#connectObject



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

def connect
  if use_ssl?
    io.connect
    verify_hostname!
  end
  io
end

#ioObject



39
40
41
42
43
44
45
# File 'lib/logstash-logger/device/tcp.rb', line 39

def io
  @io ||= if use_ssl?
    ssl_io
  else
    tcp_io
  end
end

#ssl_contextObject



22
23
24
25
# File 'lib/logstash-logger/device/tcp.rb', line 22

def ssl_context
  return unless use_ssl?
  @ssl_context || certificate_context
end

#use_ssl?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/logstash-logger/device/tcp.rb', line 27

def use_ssl?
  @use_ssl
end