Sha256: f52b1d559764d9128b279ff6895719d4f3de6f60191f8c7d7c4a1d77d1060496

Contents?: true

Size: 573 Bytes

Versions: 2

Compression:

Stored size: 573 Bytes

Contents

class LogStashLogger::TCPClient
  def initialize(host, port)
    @host = host
    @port = port
    @socket = nil
  end
  
  def write(event)
    begin
      connect unless @socket
      
      @socket.write("#{event.to_hash.to_json}\n")
    rescue => e
      warn "LogStashLogger::TCPClient - #{e.class} - #{e.message}"
      close
      @socket = nil
    end
  end
  
  def close
    @socket && @socket.close
  rescue => e
    warn "LogStashLogger::TCPClient - #{e.class} - #{e.message}"
  end
  
  private
  def connect
    @socket = TCPSocket.new(@host, @port)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
logstash-logger-0.2.1 lib/logstash-logger/tcp_client.rb
logstash-logger-0.2.0 lib/logstash-logger/tcp_client.rb