Class: Fluent::SystemConfig

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/fluent/system_config.rb

Defined Under Namespace

Modules: Mixin

Constant Summary collapse

SYSTEM_CONFIG_PARAMETERS =
[
  :workers, :restart_worker_interval, :root_dir, :log_level,
  :suppress_repeated_stacktrace, :emit_error_log_interval, :suppress_config_dump,
  :log_event_verbose, :ignore_repeated_log_interval, :ignore_same_log_interval,
  :without_source, :rpc_endpoint, :enable_get_dump, :process_name,
  :file_permission, :dir_permission, :counter_server, :counter_client,
  :strict_config_value, :enable_msgpack_time_support, :disable_shared_socket,
  :metrics, :enable_input_metrics, :enable_size_metrics, :enable_jit
]

Constants included from Configurable

Configurable::CONFIG_TYPE_REGISTRY

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Configurable

#config, #configure_proxy_generate, #configured_section_create, included, lookup_type, register_type

Constructor Details

#initialize(conf = nil, strict_config_value = false) ⇒ SystemConfig

Returns a new instance of SystemConfig.



128
129
130
131
132
# File 'lib/fluent/system_config.rb', line 128

def initialize(conf=nil, strict_config_value=false)
  super()
  conf ||= SystemConfig.blank_system_config
  configure(conf, strict_config_value)
end

Class Method Details

.blank_system_configObject



114
115
116
# File 'lib/fluent/system_config.rb', line 114

def self.blank_system_config
  Fluent::Config::Element.new('<SYSTEM>', '', {}, [])
end

.create(conf, strict_config_value = false) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/fluent/system_config.rb', line 106

def self.create(conf, strict_config_value=false)
  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, strict_config_value)
end

.overwrite_system_config(hash) ⇒ Object



118
119
120
121
122
123
124
125
126
# File 'lib/fluent/system_config.rb', line 118

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

Instance Method Details

#configure(conf, strict_config_value = false) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/fluent/system_config.rb', line 134

def configure(conf, strict_config_value=false)
  strict = strict_config_value
  if !strict && conf && conf.has_key?("strict_config_value")
    strict = Fluent::Config.bool_value(conf["strict_config_value"])
  end

  begin
    super(conf, strict)
  rescue ConfigError => e
    $log.error "config error in:\n#{conf}"
    $log.error 'config error', error: e
    $log.debug_backtrace
    exit!(1)
  end

  @log_level = Log.str_to_level(@log_level.to_s) if @log_level
end

#dupObject



152
153
154
155
156
157
158
# File 'lib/fluent/system_config.rb', line 152

def dup
  s = SystemConfig.new
  SYSTEM_CONFIG_PARAMETERS.each do |param|
    s.__send__("#{param}=", instance_variable_get("@#{param}"))
  end
  s
end

#overwrite_variables(**opt) ⇒ Object



160
161
162
163
164
165
166
# File 'lib/fluent/system_config.rb', line 160

def overwrite_variables(**opt)
  SYSTEM_CONFIG_PARAMETERS.each do |param|
    if opt.key?(param) && !opt[param].nil? && instance_variable_defined?("@#{param}")
      instance_variable_set("@#{param}", opt[param])
    end
  end
end