module Fluent::Config

Constants

ARRAY_TYPE
BOOL_TYPE
ENUM_TYPE
FLOAT_TYPE
HASH_TYPE
INTEGER_TYPE
REFORMAT_VALUE
SIZE_TYPE
STRING_TYPE
TIME_TYPE

Public Class Methods

bool_value(str) click to toggle source
# File lib/fluent/config/types.rb, line 53
def self.bool_value(str)
  return nil if str.nil?
  case str.to_s
  when 'true', 'yes'
    true
  when 'false', 'no'
    false
  when ''
    true
  else
    nil
  end
end
new(name = '') click to toggle source
# File lib/fluent/config.rb, line 52
def self.new(name = '')
  Element.new(name, '', {}, [])
end
parse(str, fname, basepath = Dir.pwd, v1_config = nil, syntax: :v1) click to toggle source
# File lib/fluent/config.rb, line 23
def self.parse(str, fname, basepath = Dir.pwd, v1_config = nil, syntax: :v1)
  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)
  when :v0
    # TODO: show deprecated message in v1
    require 'fluent/config/parser'
    Parser.parse(str, fname, basepath)
  when :ruby
    require 'fluent/config/dsl'
    Config::DSL::Parser.parse(str, File.join(basepath, fname))
  else
    raise "[BUG] unknown configuration parser specification:'#{parser}'"
  end
end
size_value(str) click to toggle source
# File lib/fluent/config/types.rb, line 23
def self.size_value(str)
  case str.to_s
  when /([0-9]+)k/
    $~[1].to_i * 1024
  when /([0-9]+)m/
    $~[1].to_i * (1024 ** 2)
  when /([0-9]+)g/
    $~[1].to_i * (1024 ** 3)
  when /([0-9]+)t/
    $~[1].to_i * (1024 ** 4)
  else
    str.to_i
  end
end
time_value(str) click to toggle source
# File lib/fluent/config/types.rb, line 38
def self.time_value(str)
  case str.to_s
  when /([0-9]+)s/
    $~[1].to_i
  when /([0-9]+)m/
    $~[1].to_i * 60
  when /([0-9]+)h/
    $~[1].to_i * 60 * 60
  when /([0-9]+)d/
    $~[1].to_i * 24 * 60 * 60
  else
    str.to_f
  end
end