Class: Fluent::ParserOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::ParserOutput
- Defined in:
- lib/fluent/plugin/out_parser.rb
Instance Attribute Summary collapse
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #emit(tag, es, chain) ⇒ Object
-
#initialize ⇒ ParserOutput
constructor
A new instance of ParserOutput.
Constructor Details
#initialize ⇒ ParserOutput
Returns a new instance of ParserOutput.
20 21 22 23 |
# File 'lib/fluent/plugin/out_parser.rb', line 20 def initialize super require 'time' end |
Instance Attribute Details
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
18 19 20 |
# File 'lib/fluent/plugin/out_parser.rb', line 18 def parser @parser end |
Instance Method Details
#configure(conf) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fluent/plugin/out_parser.rb', line 30 def configure(conf) super if not @tag and not @remove_prefix and not @add_prefix raise Fluent::ConfigError, "missing both of remove_prefix and add_prefix" end if @tag and (@remove_prefix or @add_prefix) raise Fluent::ConfigError, "both of tag and remove_prefix/add_prefix must not be specified" end if @remove_prefix @removed_prefix_string = @remove_prefix + '.' @removed_length = @removed_prefix_string.length end if @add_prefix @added_prefix_string = @add_prefix + '.' end @parser = Fluent::TextParser.new @parser.estimate_current_event = false @parser.configure(conf) if !@time_parse && @parser.parser.respond_to?("time_key=".to_sym) # disable parse time @parser.parser.time_key = nil end self end |
#emit(tag, es, chain) ⇒ Object
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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/fluent/plugin/out_parser.rb', line 58 def emit(tag, es, chain) tag = if @tag @tag else if @remove_prefix and ( (tag.start_with?(@removed_prefix_string) and tag.length > @removed_length) or tag == @remove_prefix) tag = tag[@removed_length..-1] end if @add_prefix tag = if tag and tag.length > 0 @added_prefix_string + tag else @add_prefix end end tag end es.each do |time,record| raw_value = record[@key_name] if raw_value.nil? log.warn "#{@key_name} does not exist" unless @ignore_key_not_exist handle_parsed(tag, record, time, {}) if @reserve_data next end begin @parser.parse(raw_value) do |t,values| if values t ||= time handle_parsed(tag, record, t, values) else log.warn "pattern not match with data '#{raw_value}'" unless @suppress_parse_error_log if @reserve_data t = time handle_parsed(tag, record, time, {}) end end end rescue Fluent::TextParser::ParserError => e log.warn e. unless @suppress_parse_error_log rescue ArgumentError => e if @replace_invalid_sequence unless e..index("invalid byte sequence in") == 0 raise end replaced_string = replace_invalid_byte(raw_value) @parser.parse(replaced_string) do |t,values| if values t ||= time handle_parsed(tag, record, t, values) else log.warn "pattern not match with data '#{raw_value}'" unless @suppress_parse_error_log if @reserve_data t = time handle_parsed(tag, record, time, {}) end end end else raise end rescue => e log.warn "parse failed #{e.}" unless @suppress_parse_error_log end end chain.next end |