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, :with_source_only, :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, :source_only_buffer,
  :config_include_dir
]

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.



148
149
150
151
152
# File 'lib/fluent/system_config.rb', line 148

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



134
135
136
# File 'lib/fluent/system_config.rb', line 134

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

.create(conf, strict_config_value = false) ⇒ Object



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

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



138
139
140
141
142
143
144
145
146
# File 'lib/fluent/system_config.rb', line 138

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



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/fluent/system_config.rb', line 154

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
  @log[:forced_stacktrace_level] = Log.str_to_level(@log.forced_stacktrace_level.to_s) if force_stacktrace_level?
end

#dupObject



173
174
175
176
177
178
179
# File 'lib/fluent/system_config.rb', line 173

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

#force_stacktrace_level?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/fluent/system_config.rb', line 122

def force_stacktrace_level?
  @log.forced_stacktrace_level != :none
end

#overwrite_variables(**opt) ⇒ Object



181
182
183
184
185
186
187
# File 'lib/fluent/system_config.rb', line 181

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