Skip to content

Commit

Permalink
sytem_config: add log_path attribute in system section
Browse files Browse the repository at this point in the history
This patch will add `log_path` attribute in sytem section due to configure log file path  by System Configuration.

Signed-off-by: Watson <[email protected]>
  • Loading branch information
Watson1978 committed Aug 19, 2024
1 parent 501ec93 commit 901b501
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
9 changes: 4 additions & 5 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ def initialize(cl_opt)
@inline_config = opt[:inline_config]
@use_v1_config = opt[:use_v1_config]
@conf_encoding = opt[:conf_encoding]
@log_path = opt[:log_path]
@show_plugin_config = opt[:show_plugin_config]
@libs = opt[:libs]
@plugin_dirs = opt[:plugin_dirs]
Expand Down Expand Up @@ -588,7 +587,7 @@ def options
'config_path' => @config_path,
'pid_file' => @daemonize,
'plugin_dirs' => @plugin_dirs,
'log_path' => @log_path,
'log_path' => @system_config.log_path,
'root_dir' => @system_config.root_dir,
}
end
Expand Down Expand Up @@ -694,11 +693,11 @@ def setup_global_logger(supervisor: false)
@log_rotate_size ||= system_config.log.rotate_size

rotate = @log_rotate_age || @log_rotate_size
actual_log_path = @log_path
actual_log_path = system_config.log_path

# We need to prepare a unique path for each worker since Windows locks files.
if Fluent.windows? && rotate && @log_path && @log_path != "-"
actual_log_path = Fluent::Log.per_process_path(@log_path, process_type, worker_id)
if Fluent.windows? && rotate && system_config.log_path && system_config.log_path != "-"
actual_log_path = Fluent::Log.per_process_path(system_config.log_path, process_type, worker_id)
end

if actual_log_path && actual_log_path != "-"
Expand Down
3 changes: 2 additions & 1 deletion lib/fluent/system_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SystemConfig
include Configurable

SYSTEM_CONFIG_PARAMETERS = [
:workers, :restart_worker_interval, :root_dir, :log_level,
:workers, :restart_worker_interval, :root_dir, :log_level, :log_path,
: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,
Expand All @@ -35,6 +35,7 @@ class SystemConfig
config_param :restart_worker_interval, :time, default: 0
config_param :root_dir, :string, default: nil
config_param :log_level, :enum, list: [:trace, :debug, :info, :warn, :error, :fatal], default: 'info'
config_param :log_path, :string, default: nil
config_param :suppress_repeated_stacktrace, :bool, default: nil
config_param :ignore_repeated_log_interval, :time, default: nil
config_param :ignore_same_log_interval, :time, default: nil
Expand Down
2 changes: 2 additions & 0 deletions test/config/test_system_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def parse_text(text)
assert_equal(0, sc.restart_worker_interval)
assert_nil(sc.root_dir)
assert_equal(Fluent::Log::LEVEL_INFO, sc.log_level)
assert_nil(sc.log_path)
assert_nil(sc.suppress_repeated_stacktrace)
assert_nil(sc.ignore_repeated_log_interval)
assert_nil(sc.emit_error_log_interval)
Expand All @@ -86,6 +87,7 @@ def parse_text(text)
'restart_worker_interval' => ['restart_worker_interval', 60],
'root_dir' => ['root_dir', File.join(TMP_DIR, 'root')],
'log_level' => ['log_level', 'error'],
'log_path' => ['log_path', '/tmp/fluentd.log'],
'suppress_repeated_stacktrace' => ['suppress_repeated_stacktrace', true],
'ignore_repeated_log_interval' => ['ignore_repeated_log_interval', 10],
'log_event_verbose' => ['log_event_verbose', true],
Expand Down
5 changes: 5 additions & 0 deletions test/test_supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def test_system_config
enable_get_dump true
process_name "process_name"
log_level info
log_path /tmp/fluentd.log
root_dir #{@tmp_root_dir}
<log>
format json
Expand Down Expand Up @@ -93,6 +94,7 @@ def test_system_config
assert_equal true, sys_conf.enable_get_dump
assert_equal "process_name", sys_conf.process_name
assert_equal 2, sys_conf.log_level
assert_equal "/tmp/fluentd.log", sys_conf.log_path
assert_equal @tmp_root_dir, sys_conf.root_dir
assert_equal :json, sys_conf.log.format
assert_equal '%Y', sys_conf.log.time_format
Expand Down Expand Up @@ -132,6 +134,7 @@ def test_system_config
enable_get_dump: true
process_name: "process_name"
log_level: info
log_path: /tmp/fluentd.log
root_dir: !fluent/s "#{@tmp_root_dir}"
log:
format: json
Expand Down Expand Up @@ -160,6 +163,7 @@ def test_system_config
true,
"process_name",
2,
"/tmp/fluentd.log",
@tmp_root_dir,
:json,
'%Y',
Expand All @@ -179,6 +183,7 @@ def test_system_config
sys_conf.enable_get_dump,
sys_conf.process_name,
sys_conf.log_level,
sys_conf.log_path,
sys_conf.root_dir,
sys_conf.log.format,
sys_conf.log.time_format,
Expand Down

0 comments on commit 901b501

Please sign in to comment.