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

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

Instance Method Summary collapse

Methods inherited from Node

#text_value_for_comments

Instance Method Details

#compileObject



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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/logstash/config/config_ast.rb', line 94

def compile
  LogStash::Config::AST.defered_conditionals = []
  LogStash::Config::AST.defered_conditionals_index = 0
  LogStash::Config::AST.plugin_instance_index = 0
  code = []

  code << <<-CODE
    @inputs = []
    @filters = []
    @outputs = []
    @periodic_flushers = []
    @shutdown_flushers = []
    @generated_objects = {}
  CODE

  sections = recursive_select(LogStash::Config::AST::PluginSection)
  sections.each do |s|
    code << s.compile_initializer
  end

  # start inputs
  definitions = []

  ["filter", "output"].each do |type|
    # defines @filter_func and @output_func

    # This need to be defined as a singleton method
    # so each instance of the pipeline has his own implementation
    # of the output/filter function
    definitions << "define_singleton_method :#{type}_func do |event|"
    definitions << "  targeted_outputs = []" if type == "output"
    definitions << "  events = [event]" if type == "filter"
    definitions << "  @logger.debug? && @logger.debug(\"#{type} received\", \"event\" => event.to_hash)"

    sections.select { |s| s.plugin_type.text_value == type }.each do |s|
      definitions << s.compile.split("\n", -1).map { |e| "  #{e}" }
    end

    definitions << "  events" if type == "filter"
    definitions << "  targeted_outputs" if type == "output"
    definitions << "end"
  end

  code += definitions.join("\n").split("\n", -1).collect { |l| "  #{l}" }

  code += LogStash::Config::AST.defered_conditionals

  return code.join("\n")
end