lib/fluent/plugin/formatter_jq.rb in fluent-plugin-jq-0.2.0 vs lib/fluent/plugin/formatter_jq.rb in fluent-plugin-jq-0.3.0

- old
+ new

@@ -39,16 +39,20 @@ super @jq = @jq_program unless @jq raise Fluent::ConfigError, "jq is required." unless @jq - JQ::Core.new @jq + @jq_filter = JQ::Core.new @jq rescue JQ::Error raise Fluent::ConfigError, "Could not parse jq filter #{@jq}, error: #{$!.message}" end def format(tag, time, record) - item = JQ(MultiJson.dump(record)).search(@jq).first + item = [].tap { |buf| + @jq_filter.update(MultiJson.dump(record), false) { |r| + buf << MultiJson.load("[#{r}]").first + } + }.first return item if item.instance_of?(String) MultiJson.dump item rescue JQ::Error msg = "Failed to format #{record.to_json} with #{@jq}, error: #{$!.message}" log.error msg