class Fluent::SystemConfig

Constants

SYSTEM_CONFIG_PARAMETERS

Public Class Methods

blank_system_config() click to toggle source
# File lib/fluent/system_config.rb, line 84
def self.blank_system_config
  Fluent::Config::Element.new('<SYSTEM>', '', {}, [])
end
create(conf) click to toggle source
# File lib/fluent/system_config.rb, line 76
def self.create(conf)
  systems = conf.elements(name: 'system')
  return SystemConfig.new if systems.empty?
  raise Fluent::ConfigError, "<system> is duplicated. <system> should be only one" if systems.size > 1

  SystemConfig.new(systems.first)
end
new(conf=nil) click to toggle source
Calls superclass method Fluent::Configurable.new
# File lib/fluent/system_config.rb, line 98
def initialize(conf=nil)
  super()
  conf ||= SystemConfig.blank_system_config
  configure(conf)
end
overwrite_system_config(hash) { || ... } click to toggle source
# File lib/fluent/system_config.rb, line 88
def self.overwrite_system_config(hash)
  older = defined?($_system_config) ? $_system_config : nil
  begin
    $_system_config = SystemConfig.new(Fluent::Config::Element.new('system', '', hash, []))
    yield
  ensure
    $_system_config = older
  end
end

Public Instance Methods

apply(supervisor) click to toggle source
# File lib/fluent/system_config.rb, line 145
def apply(supervisor)
  system = self
  supervisor.instance_eval {
    SYSTEM_CONFIG_PARAMETERS.each do |param|
      param_value = system.__send__(param)
      next if param_value.nil?

      case param
      when :log_level
        @log.level = @log_level = param_value
      when :emit_error_log_interval
        @suppress_interval = param_value
      else
        instance_variable_set("@#{param}", param_value)
      end
    end
    #@counter_server = system.counter_server unless system.counter_server.nil?
    #@counter_client = system.counter_client unless system.counter_client.nil?
  }
end
attach(supervisor) click to toggle source
# File lib/fluent/system_config.rb, line 118
def attach(supervisor)
  system = self
  supervisor.instance_eval {
    SYSTEM_CONFIG_PARAMETERS.each do |param|
      case param
      when :rpc_endpoint, :enable_get_dump, :process_name, :file_permission, :dir_permission, :counter_server, :counter_client
        next # doesn't exist in command line options
      when :emit_error_log_interval
        system.emit_error_log_interval = @suppress_interval if @suppress_interval
      when :log_level
        ll_value = instance_variable_get("@log_level")
        # info level can't be specified via command line option.
        # log_level is info here, it is default value and <system>'s log_level should be applied if exists.
        if ll_value != Fluent::Log::LEVEL_INFO
          system.log_level = ll_value
        end
      else
        next unless instance_variable_defined?("@#{param}")
        supervisor_value = instance_variable_get("@#{param}")
        next if supervisor_value.nil? # it's not configured by command line options

        system.send("#{param}=", supervisor_value)
      end
    end
  }
end
configure(conf) click to toggle source
Calls superclass method Fluent::Configurable#configure
# File lib/fluent/system_config.rb, line 104
def configure(conf)
  super

  @log_level = Log.str_to_level(@log_level.to_s) if @log_level
end
dup() click to toggle source
# File lib/fluent/system_config.rb, line 110
def dup
  s = SystemConfig.new
  SYSTEM_CONFIG_PARAMETERS.each do |param|
    s.__send__("#{param}=", instance_variable_get("@#{param}"))
  end
  s
end