Class: LogStashLogger::Device::HTTP
- Inherits:
-
Connectable
- Object
- Base
- Connectable
- LogStashLogger::Device::HTTP
- Defined in:
- lib/logstash-logger/device/http.rb
Overview
Rudimentary write to Logstash HTTP Input relying on buffering rather than persistent HTTP connections for efficiency.
Instance Attribute Summary
Attributes inherited from Connectable
Attributes inherited from Base
Instance Method Summary collapse
- #connect ⇒ Object
-
#initialize(opts) ⇒ HTTP
constructor
A new instance of HTTP.
- #write_batch(messages, _group = nil) ⇒ Object
- #write_one(message) ⇒ Object
Methods inherited from Connectable
#close, #connected?, #flush, #on_full_buffer_receive, #reconnect, #reset, #to_io, #with_connection, #write
Methods included from Buffer
#buffer_flush, #buffer_full?, #buffer_initialize, #buffer_receive, #reset_buffer
Methods inherited from Base
#close, #close!, #flush, #reset, #to_io, #unrecoverable_error?, #write
Constructor Details
#initialize(opts) ⇒ HTTP
Returns a new instance of HTTP.
11 12 13 14 |
# File 'lib/logstash-logger/device/http.rb', line 11 def initialize(opts) super @url = URI(opts[:url]) end |
Instance Method Details
#connect ⇒ Object
16 17 18 |
# File 'lib/logstash-logger/device/http.rb', line 16 def connect # no-op end |
#write_batch(messages, _group = nil) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/logstash-logger/device/http.rb', line 24 def write_batch(, _group = nil) # Logstash HTTP input expects JSON array instead of lines of JSON body = "[#{.join(',')}]" resp = Net::HTTP.post @url, body, {"Content-Type" => "application/json"} raise resp. if Net::HTTPError === resp end |
#write_one(message) ⇒ Object
20 21 22 |
# File 'lib/logstash-logger/device/http.rb', line 20 def write_one() write_batch([]) end |