Class: Rack::Logstash::Transport
- Inherits:
-
Object
- Object
- Rack::Logstash::Transport
- Defined in:
- lib/rack/logstash/transport.rb
Instance Method Summary collapse
- #drain ⇒ Object
-
#initialize(url) ⇒ Transport
constructor
A new instance of Transport.
- #send(msg) ⇒ Object
Constructor Details
#initialize(url) ⇒ Transport
Returns a new instance of Transport.
9 10 11 12 13 14 |
# File 'lib/rack/logstash/transport.rb', line 9 def initialize(url) @url = url @backlog = [] @blmutex = Mutex.new @sender = sender_thread end |
Instance Method Details
#drain ⇒ Object
30 31 32 33 34 |
# File 'lib/rack/logstash/transport.rb', line 30 def drain until @blmutex.synchronize { @backlog.empty? } sleep 0.001 end end |
#send(msg) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rack/logstash/transport.rb', line 16 def send(msg) begin @blmutex.synchronize { @backlog << msg.to_json } @sender.run rescue EncodingError, JSON::JSONError => ex $stderr.puts "Serialisation error: #{ex.} (#{ex.class})" $stderr.puts "Message: #{msg.inspect}" $stderr.puts ex.backtrace.map { |l| " #{l}" } rescue StandardError => ex $stderr.puts "Failed to send message: #{ex.} (#{ex.class})" $stderr.puts ex.backtrace.map { |l| " #{l}" } end end |