From 0e540fe32283d2a1486bf4b2befbd36430db8df8 Mon Sep 17 00:00:00 2001 From: Daijiro Fukuda Date: Mon, 29 May 2023 14:43:58 +0900 Subject: [PATCH] Logger: Fix logger setup failure on Windows with rotate but no log path Fix a bug of f8b73a571954b4a7cfb137cb521edeb370f3f0b5 (#4091). Before that fix, Fluentd can start if rotation is enabled but the log file path is not specified. After that fix, the logger setup starts to fail on Windows. This fix solves it. Signed-off-by: Daijiro Fukuda --- lib/fluent/supervisor.rb | 2 +- test/test_supervisor.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/fluent/supervisor.rb b/lib/fluent/supervisor.rb index 543ce6a32d..5c1018c9c7 100644 --- a/lib/fluent/supervisor.rb +++ b/lib/fluent/supervisor.rb @@ -697,7 +697,7 @@ def setup_global_logger(supervisor: false) actual_log_path = @log_path # We need to prepare a unique path for each worker since Windows locks files. - if Fluent.windows? && rotate + if Fluent.windows? && rotate && @log_path && @log_path != "-" actual_log_path = Fluent::Log.per_process_path(@log_path, process_type, worker_id) end diff --git a/test/test_supervisor.rb b/test/test_supervisor.rb index 64915a7e4a..d684b5eeb5 100644 --- a/test/test_supervisor.rb +++ b/test/test_supervisor.rb @@ -621,6 +621,19 @@ def test_logger_with_rotate_age_and_rotate_size(rotate_age) assert_equal 10, $log.out.instance_variable_get(:@shift_size) end + def test_can_start_with_rotate_but_no_log_path + config_path = "#{@tmp_dir}/empty.conf" + write_config config_path, "" + + sv = Fluent::Supervisor.new( + config_path: config_path, + log_rotate_age: 5, + ) + sv.__send__(:setup_global_logger) + + assert_true $log.stdout? + end + sub_test_case "system log rotation" do def parse_text(text) basepath = File.expand_path(File.dirname(__FILE__) + '/../../')