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

Inherits:
Node
  • Object
show all
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::NAND_METHOD, LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers::OR_METHOD, LogStashCompilerLSCLGrammar::LogStash::Compiler::LSCL::AST::Helpers::XOR_METHOD

Instance Method Summary collapse

Methods inherited from Node

#text_value_for_comments

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

Instance Method Details

#compileObject



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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/logstash/config/config_ast.rb', line 49

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



44
45
46
# File 'lib/logstash/config/config_ast.rb', line 44

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