Class: Fluent::Plugin::JqParser
- Inherits:
-
Parser
- Object
- Parser
- Fluent::Plugin::JqParser
- Defined in:
- lib/fluent/plugin/parser_jq.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
-
#initialize ⇒ JqParser
constructor
A new instance of JqParser.
- #parse(text) ⇒ Object
Constructor Details
#initialize ⇒ JqParser
Returns a new instance of JqParser.
27 28 29 30 |
# File 'lib/fluent/plugin/parser_jq.rb', line 27 def initialize super require "jq" end |
Instance Method Details
#configure(conf) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/fluent/plugin/parser_jq.rb', line 32 def configure(conf) super @jq_filter = JQ::Core.new @jq rescue JQ::Error raise Fluent::ConfigError, "Could not parse jq filter: #{@jq}, error: #{$!.}" end |
#parse(text) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fluent/plugin/parser_jq.rb', line 39 def parse(text) record = [].tap { |buf| @jq_filter.update(MultiJson.dump(text), false) { |r| buf << MultiJson.load("[#{r}]").first } }.first if record.is_a?(Hash) yield parse_time(record), record else log.error "jq filter #{@jq} did not return a hash, skip this record." end rescue JQ::Error log.error "Failed to parse #{text} with #{@jq}, error: #{$!.}" nil end |