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



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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/logstash/config/config_ast.rb', line 113

def compile
  LogStash::Config::AST.deferred_conditionals = []
  LogStash::Config::AST.deferred_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)" if type == "output"
    definitions << "  @logger.debug? && events.each { |e| @logger.debug(\"#{type} received\", \"event\" => e.to_hash)}" if type == "filter"

    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.deferred_conditionals

  return code.join("\n")
end

#process_escape_sequences=(val) ⇒ Object



108
109
110
# File 'lib/logstash/config/config_ast.rb', line 108

def process_escape_sequences=(val)
  set_meta(PROCESS_ESCAPE_SEQUENCES, val)
end