Class: LogStash::Config::AST::PluginSection

Inherits:
Node
  • Object
show all
Defined in:
lib/logstash/config/config_ast.rb

Constant Summary collapse

@@i =

Global plugin numbering for the janky instance variable naming we use like @filter_<name>_1

0

Instance Method Summary collapse

Methods inherited from Node

#text_value_for_comments

Instance Method Details

#compile_initializerObject

Generate ruby code to initialize all the plugins.



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/logstash/config/config_ast.rb', line 138

def compile_initializer
  generate_variables
  code = []
  @variables.each do |plugin, name|


    code << <<-CODE
      #{name} = #{plugin.compile_initializer}
      @#{plugin.plugin_type}s << #{name}
    CODE

    # The flush method for this filter.
    if plugin.plugin_type == "filter"

      code << <<-CODE
        #{name}_flush = lambda do |options, &block|
          @logger.debug? && @logger.debug(\"Flushing\", :plugin => #{name})

          events = #{name}.flush(options)

          return if events.nil? || events.empty?

          @logger.debug? && @logger.debug(\"Flushing\", :plugin => #{name}, :events => events)

          #{plugin.compile_starting_here.gsub(/^/, "  ")}

          events.each{|e| block.call(e)}
        end

        if #{name}.respond_to?(:flush)
          @periodic_flushers << #{name}_flush if #{name}.periodic_flush
          @shutdown_flushers << #{name}_flush
        end
      CODE

    end
  end
  return code.join("\n")
end

#generate_variablesObject



183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/logstash/config/config_ast.rb', line 183

def generate_variables
  return if !@variables.nil?
  @variables = {}
  plugins = recursive_select(Plugin)

  plugins.each do |plugin|
    # Unique number for every plugin.
    @@i += 1
    # store things as ivars, like @filter_grok_3
    var = "@#{plugin.plugin_type}_#{plugin.plugin_name}_#{@@i}"
    @variables[plugin] = var
  end
  return @variables
end

#variable(object) ⇒ Object



178
179
180
181
# File 'lib/logstash/config/config_ast.rb', line 178

def variable(object)
  generate_variables
  return @variables[object]
end