Class: Fluent::Plugin::BaritoTransport

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/barito_transport.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(produce_url, logger) ⇒ BaritoTransport

Returns a new instance of BaritoTransport.



8
9
10
11
# File 'lib/fluent/plugin/barito_transport.rb', line 8

def initialize(produce_url, logger)
  @produce_url = produce_url
  @logger = logger
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/fluent/plugin/barito_transport.rb', line 6

def logger
  @logger
end

#produce_urlObject

Returns the value of attribute produce_url.



6
7
8
# File 'lib/fluent/plugin/barito_transport.rb', line 6

def produce_url
  @produce_url
end

Instance Method Details

#send(timber, header) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/fluent/plugin/barito_transport.rb', line 13

def send(timber, header)
  begin
    RestClient.post @produce_url, timber.to_json, header
  rescue Exception => e
    @logger.error [e.message, e.response, header].join(', ')
  end
end

#send_compressed(timber, header) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fluent/plugin/barito_transport.rb', line 21

def send_compressed(timber, header)
  begin
    header['Content-Encoding'] = 'gzip'

    gz = Zlib::GzipWriter.new(StringIO.new)
    gz << timber.to_json
    RestClient.post @produce_url, gz.close.string, header
  rescue Exception => e
    puts(header)
    @logger.error [e.message, e.response, Hash[header.collect{|k,v| [k.to_s, v]}]].join(', ')
  end
end