Method: Fluent::Config.parse

Defined in:
lib/fluent/config.rb

.parse(str, fname, basepath = Dir.pwd, v1_config = nil, syntax: :v1, on_file_parsed: nil) ⇒ Object



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
# File 'lib/fluent/config.rb', line 55

def self.parse(str, fname, basepath = Dir.pwd, v1_config = nil, syntax: :v1, on_file_parsed: nil)
  parser = if fname =~ /\.rb$/ || syntax == :ruby
             :ruby
           elsif v1_config.nil?
             case syntax
             when :v1 then :v1
             when :v0 then :v0
             else
               raise ArgumentError, "Unknown Fluentd configuration syntax: '#{syntax}'"
             end
           elsif v1_config then :v1
           else :v0
           end
  case parser
  when :v1
    require 'fluent/config/v1_parser'
    V1Parser.parse(str, fname, basepath, Kernel.binding, on_file_parsed: on_file_parsed)
  when :v0
    # TODO: show deprecated message in v1
    require 'fluent/config/parser'
    Parser.parse(str, fname, basepath)
  when :ruby
    require 'fluent/config/dsl'
    $log.warn("Ruby DSL configuration format is deprecated. Please use original configuration format. https://docs.fluentd.org/configuration/config-file") if $log
    Config::DSL::Parser.parse(str, File.join(basepath, fname))
  else
    raise "[BUG] unknown configuration parser specification:'#{parser}'"
  end
end