Class: Fluent::ParserOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_parser.rb

Instance Method Summary collapse

Constructor Details

#initializeParserOutput

Returns a new instance of ParserOutput.



12
13
14
15
# File 'lib/fluent/plugin/out_parser.rb', line 12

def initialize
  super
  require 'time'
end

Instance Method Details

#configure(conf) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fluent/plugin/out_parser.rb', line 17

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 = FluentExt::TextParser.new
  @parser.configure(conf)
end

#emit(tag, es, chain) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
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
# File 'lib/fluent/plugin/out_parser.rb', line 38

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
  if @reserve_data
    es.each {|time,record|
      value = record[@key_name]
      t,values = if value
                   @parser.parse(value)
                 else
                   [nil, {}]
                 end
      t ||= time
      record.update(values)
      Fluent::Engine.emit(tag, t, record)
    }
  else
    es.each {|time,record|
      value = record[@key_name]
      t,values = if value
                   @parser.parse(value)
                 else
                   [nil, {}]
                 end
      t ||= time
      Fluent::Engine.emit(tag, t, values)
    }
  end
  chain.next
end