Skip to content

Commit

Permalink
Logger: Fix logger setup failure on Windows with rotate but no log path
Browse files Browse the repository at this point in the history
Fix a bug of f8b73a5 (fluent#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 <[email protected]>
  • Loading branch information
daipom committed May 29, 2023
1 parent dc7e4b2 commit 0e540fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions test/test_supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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__) + '/../../')
Expand Down

0 comments on commit 0e540fe

Please sign in to comment.