lib/logstash-logger/tcp_client.rb in logstash-logger-0.1.0 vs lib/logstash-logger/tcp_client.rb in logstash-logger-0.2.0

- old
+ new

@@ -1,20 +1,27 @@ 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}" - @socket && @socket.close rescue nil + 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) \ No newline at end of file