Sha256: 0bf1daf0399e1221f9d2f415487672bdb5bf13c9b8eccaae1026f999fdc97c8a
Contents?: true
Size: 695 Bytes
Versions: 3
Compression:
Stored size: 695 Bytes
Contents
class LogStashLogger::Socket def initialize(host, port, socket_type = :udp) @host = host @port = port @type = socket_type @socket = nil end def write(event) begin connect unless @socket @socket.write("#{event.to_hash.to_json}\n") rescue => e warn "#{self.class} - #{e.class} - #{e.message}" close @socket = nil end end def close @socket && @socket.close rescue => e warn "#{self.class} - #{e.class} - #{e.message}" end private def connect @socket = case @type when :udp then UDPSocket.new.tap {|s| s.connect(@host, @port)} when :tcp then TCPSocket.new(@host, @port) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
logstash-logger-0.4.1 | lib/logstash-logger/socket.rb |
logstash-logger-0.4.0 | lib/logstash-logger/socket.rb |
logstash-logger-0.3.0 | lib/logstash-logger/socket.rb |