Class: Sysloggly::Clients::Networklog

Inherits:
Object
  • Object
show all
Defined in:
lib/sysloggly/clients/networklog.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_uri) ⇒ Sysloggly::Client::Networklog

Creates a new client that conforms to the Logger::LogDevice specification.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sysloggly/clients/networklog.rb', line 12

def initialize(input_uri)
  @input_uri = input_uri

  case @input_uri.scheme
  when "udp"
    @socket = UDPSocket.new
    @socket.connect(@input_uri.host, @input_uri.port)
  when "tcp"
    @socket = TCPSocket.new(@input_uri.host, @input_uri.port)
    @socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1)
    @socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true)
  end
end

Instance Attribute Details

#input_uriObject (readonly)

Returns the value of attribute input_uri.



6
7
8
# File 'lib/sysloggly/clients/networklog.rb', line 6

def input_uri
  @input_uri
end

#socketObject (readonly)

Returns the value of attribute socket.



6
7
8
# File 'lib/sysloggly/clients/networklog.rb', line 6

def socket
  @socket
end

Instance Method Details

#closeObject

Required by Logger::LogDevice



40
41
42
# File 'lib/sysloggly/clients/networklog.rb', line 40

def close
  @socket.close
end

#write(message) ⇒ Object

Required by Logger::LogDevice



29
30
31
32
33
34
35
# File 'lib/sysloggly/clients/networklog.rb', line 29

def write(message)
  begin
    @socket.send(message, 0)
  rescue Timeout::Error => e
    STDOUT.puts "WARNING: Timeout::Error posting message: #{message}"
  end
end