Class: Fluent::Plugin::ParserFilter
- Defined in:
- lib/fluent/plugin/filter_parser.rb
Constant Summary collapse
- FAILED_RESULT =
reduce allocation cost
[nil, nil].freeze
- REPLACE_CHAR =
'?'.freeze
Constants included from Configurable
Configurable::CONFIG_TYPE_REGISTRY
Instance Attribute Summary collapse
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
Attributes inherited from Filter
Attributes included from Fluent::PluginLoggerMixin
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Filter
#filter, #filter_stream, #initialize
Methods included from Fluent::PluginHelper::Mixin
Methods included from Fluent::PluginLoggerMixin
included, #initialize, #terminate
Methods included from Fluent::PluginId
#initialize, #plugin_id, #plugin_id_configured?, #plugin_id_for_test?, #plugin_root_dir
Methods inherited from Base
#after_shutdown, #after_shutdown?, #after_start, #after_started?, #before_shutdown, #before_shutdown?, #close, #closed?, #configured?, #context_router, #context_router=, #fluentd_worker_id, #has_router?, #initialize, #inspect, #multi_workers_ready?, #plugin_root_dir, #shutdown, #shutdown?, #start, #started?, #stop, #stopped?, #string_safe_encoding, #terminate, #terminated?
Methods included from SystemConfig::Mixin
#system_config, #system_config_override
Methods included from Configurable
#config, #configure_proxy_generate, #configured_section_create, included, #initialize, lookup_type, register_type
Constructor Details
This class inherits a constructor from Fluent::Plugin::Filter
Instance Attribute Details
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
37 38 39 |
# File 'lib/fluent/plugin/filter_parser.rb', line 37 def parser @parser end |
Instance Method Details
#configure(conf) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/fluent/plugin/filter_parser.rb', line 39 def configure(conf) compat_parameters_convert(conf, :parser) super @parser = parser_create end |
#filter_with_time(tag, time, record) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/fluent/plugin/filter_parser.rb', line 50 def filter_with_time(tag, time, record) raw_value = record[@key_name] if raw_value.nil? if @emit_invalid_record_to_error router.emit_error_event(tag, time, record, ArgumentError.new("#{@key_name} does not exist")) end if @reserve_data return time, handle_parsed(tag, record, time, {}) else return FAILED_RESULT end end begin @parser.parse(raw_value) do |t, values| if values t = if @reserve_time time else t.nil? ? time : t end r = handle_parsed(tag, record, t, values) return t, r else if @emit_invalid_record_to_error router.emit_error_event(tag, time, record, Fluent::Plugin::Parser::ParserError.new("pattern not match with data '#{raw_value}'")) end if @reserve_data t = time r = handle_parsed(tag, record, time, {}) return t, r else return FAILED_RESULT end end end rescue Fluent::Plugin::Parser::ParserError => e if @emit_invalid_record_to_error raise e else return FAILED_RESULT end rescue ArgumentError => e raise unless @replace_invalid_sequence raise unless e..index("invalid byte sequence in") == 0 raw_value = raw_value.scrub(REPLACE_CHAR) retry rescue => e if @emit_invalid_record_to_error raise Fluent::Plugin::Parser::ParserError, "parse failed #{e.}" else return FAILED_RESULT end end end |