Class: LogStash::Config::AST::PluginSection
- Inherits:
-
Node
- Object
- Treetop::Runtime::SyntaxNode
- Node
- LogStash::Config::AST::PluginSection
- Defined in:
- lib/logstash/config/config_ast.rb
Constant Summary
Constants included from LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers
LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers::AND_METHOD, LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers::BOOLEAN_DSL_METHOD_SIGNATURE, LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers::NAND_METHOD, LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers::OR_METHOD, LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers::XOR_METHOD
Instance Method Summary collapse
-
#compile_initializer ⇒ Object
Generate ruby code to initialize all the plugins.
- #generate_variables ⇒ Object
-
#initialize(*args) ⇒ PluginSection
constructor
Global plugin numbering for the janky instance variable naming we use like @filter_<name>_1.
- #variable(object) ⇒ Object
Methods inherited from Node
Methods included from LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers
#base_id, #base_protocol, #base_source_with_metadata, #base_source_with_metadata=, #compose, #compose_for, #jdsl, jdsl, #line_and_column, #source_meta
Constructor Details
#initialize(*args) ⇒ PluginSection
Global plugin numbering for the janky instance variable naming we use like @filter_<name>_1
146 147 148 |
# File 'lib/logstash/config/config_ast.rb', line 146 def initialize(*args) super(*args) end |
Instance Method Details
#compile_initializer ⇒ Object
Generate ruby code to initialize all the plugins.
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 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/logstash/config/config_ast.rb', line 151 def compile_initializer generate_variables code = [] @variables.each do |plugin, name| code << <<-CODE @generated_objects[:#{name}] = #{plugin.compile_initializer} @#{plugin.plugin_type}s << @generated_objects[:#{name}] CODE # The flush method for this filter. if plugin.plugin_type == "filter" code << <<-CODE @generated_objects[:#{name}_flush] = lambda do |options, &block| @logger.debug? && @logger.debug(\"Flushing\", :plugin => @generated_objects[:#{name}]) events = @generated_objects[:#{name}].flush(options) return if events.nil? || events.empty? @logger.debug? && @logger.debug(\"Flushing\", :plugin => @generated_objects[:#{name}], :events => events.map { |x| x.to_hash }) #{plugin.compile_starting_here.gsub(/^/, " ")} events.each{|e| block.call(e)} end if !@generated_objects[:#{name}].nil? && @generated_objects[:#{name}].has_flush @periodic_flushers << @generated_objects[:#{name}_flush] if @generated_objects[:#{name}].periodic_flush @shutdown_flushers << @generated_objects[:#{name}_flush] end CODE end end return code.join("\n") end |
#generate_variables ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/logstash/config/config_ast.rb', line 196 def generate_variables return if !@variables.nil? @variables = {} plugins = recursive_select(Plugin) plugins.each do |plugin| # Unique number for every plugin. LogStash::Config::AST.plugin_instance_index += 1 # store things as ivars, like @filter_grok_3 var = :"#{plugin.plugin_type}_#{plugin.plugin_name}_#{LogStash::Config::AST.plugin_instance_index}" # puts("var=#{var.inspect}") @variables[plugin] = var end return @variables end |
#variable(object) ⇒ Object
191 192 193 194 |
# File 'lib/logstash/config/config_ast.rb', line 191 def variable(object) generate_variables return @variables[object] end |