lib/fluent/plugin/out_http.rb in fluent-plugin-out-http-0.1.0 vs lib/fluent/plugin/out_http.rb in fluent-plugin-out-http-0.1.1

- old
+ new

@@ -1,14 +1,13 @@ -require 'json' - class Fluent::HTTPOutput < Fluent::Output Fluent::Plugin.register_output('http', self) def initialize super require 'net/http' require 'uri' + require 'yajl' end # Endpoint URL ex. localhost.local/api/ config_param :endpoint_url, :string @@ -75,11 +74,11 @@ def set_header(req, tag, time, record) req end def set_json_body(req, data) - req.body = JSON.dump(data) + req.body = Yajl.dump(data) req['Content-Type'] = 'application/json' end def create_request(tag, time, record) url = format_url(tag, time, record) @@ -107,10 +106,15 @@ rescue IOError, EOFError, SystemCallError # server didn't respond $log.warn "Net::HTTP.#{req.method.capitalize} raises exception: #{$!.class}, '#{$!.message}'" end unless res and res.is_a?(Net::HTTPSuccess) - $log.warn "failed to #{req.method} #{uri} (#{res.code} #{res.message} #{res.body})" + res_summary = if res + "#{res.code} #{res.message} #{res.body}" + else + "res=nil" + end + $log.warn "failed to #{req.method} #{uri} (#{res_summary})" end end def handle_record(tag, time, record) req, uri = create_request(tag, time, record)