From d94030b58cc5025a8a89e0f530de917364cadbfd Mon Sep 17 00:00:00 2001 From: Watson Date: Mon, 19 Aug 2024 10:57:40 +0900 Subject: [PATCH] system_config: add path attribute in system/log section This patch will add `path` attribute in sytem/log section due to configure log file path by System Configuration. Signed-off-by: Watson --- lib/fluent/supervisor.rb | 8 +++++--- lib/fluent/system_config.rb | 1 + test/config/test_system_config.rb | 2 ++ test/test_supervisor.rb | 5 +++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/fluent/supervisor.rb b/lib/fluent/supervisor.rb index 5c1018c9c7..d565abf600 100644 --- a/lib/fluent/supervisor.rb +++ b/lib/fluent/supervisor.rb @@ -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] @@ -527,13 +526,15 @@ def initialize(cl_opt) @chumask = opt[:chumask] @signame = opt[:signame] - # TODO: `@log_rotate_age` and `@log_rotate_size` should be removed + # TODO: `@log_path`, `@log_rotate_age` and `@log_rotate_size` should be removed # since it should be merged with SystemConfig in `build_system_config()`. - # We should always use `system_config.log.rotate_age` and `system_config.log.rotate_size`. + # We should always use `system_config.log.path`, `system_config.log.rotate_age` + # and `system_config.log.rotate_size`. # However, currently, there is a bug that `system_config.log` parameters # are not in `Fluent::SystemConfig::SYSTEM_CONFIG_PARAMETERS`, and these # parameters are not merged in `build_system_config()`. # Until we fix the bug of `Fluent::SystemConfig`, we need to use these instance variables. + @log_path = opt[:log_path] @log_rotate_age = opt[:log_rotate_age] @log_rotate_size = opt[:log_rotate_size] @@ -690,6 +691,7 @@ def setup_global_logger(supervisor: false) # TODO: we should remove this logic. This merging process should be done # in `build_system_config()`. + @log_path ||= system_config.log.path @log_rotate_age ||= system_config.log.rotate_age @log_rotate_size ||= system_config.log.rotate_size diff --git a/lib/fluent/system_config.rb b/lib/fluent/system_config.rb index 4919294989..917889018d 100644 --- a/lib/fluent/system_config.rb +++ b/lib/fluent/system_config.rb @@ -58,6 +58,7 @@ class SystemConfig v.to_i(8) end config_section :log, required: false, init: true, multi: false do + config_param :path, :string, default: nil config_param :format, :enum, list: [:text, :json], default: :text config_param :time_format, :string, default: '%Y-%m-%d %H:%M:%S %z' config_param :rotate_age, default: nil do |v| diff --git a/test/config/test_system_config.rb b/test/config/test_system_config.rb index a45fde5f15..c13a340a78 100644 --- a/test/config/test_system_config.rb +++ b/test/config/test_system_config.rb @@ -117,6 +117,7 @@ def parse_text(text) conf = parse_text(<<-EOS) + path /tmp/fluentd.log format json time_format %Y @@ -125,6 +126,7 @@ def parse_text(text) s = FakeSupervisor.new sc = Fluent::SystemConfig.new(conf) sc.overwrite_variables(**s.for_system_config) + assert_equal('/tmp/fluentd.log', sc.log.path) assert_equal(:json, sc.log.format) assert_equal('%Y', sc.log.time_format) end diff --git a/test/test_supervisor.rb b/test/test_supervisor.rb index d684b5eeb5..3b5b343483 100644 --- a/test/test_supervisor.rb +++ b/test/test_supervisor.rb @@ -67,6 +67,7 @@ def test_system_config log_level info root_dir #{@tmp_root_dir} + path /tmp/fluentd.log format json time_format %Y @@ -94,6 +95,7 @@ def test_system_config assert_equal "process_name", sys_conf.process_name assert_equal 2, sys_conf.log_level assert_equal @tmp_root_dir, sys_conf.root_dir + assert_equal "/tmp/fluentd.log", sys_conf.log.path assert_equal :json, sys_conf.log.format assert_equal '%Y', sys_conf.log.time_format counter_server = sys_conf.counter_server @@ -134,6 +136,7 @@ def test_system_config log_level: info root_dir: !fluent/s "#{@tmp_root_dir}" log: + path: /tmp/fluentd.log format: json time_format: "%Y" counter_server: @@ -161,6 +164,7 @@ def test_system_config "process_name", 2, @tmp_root_dir, + "/tmp/fluentd.log", :json, '%Y', '127.0.0.1', @@ -180,6 +184,7 @@ def test_system_config sys_conf.process_name, sys_conf.log_level, sys_conf.root_dir, + sys_conf.log.path, sys_conf.log.format, sys_conf.log.time_format, counter_server.bind,