Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger: Fails to launch Fluentd without specifying the path in the command line options on Windows with rotation #4187

Closed
daipom opened this issue May 29, 2023 · 1 comment · Fixed by #4188
Assignees
Labels
bug Something isn't working

Comments

@daipom
Copy link
Contributor

daipom commented May 29, 2023

Describe the bug

If you enable log rotation and don't specify the log path, then Fluentd fails to start.

nil check for @log_path to be passed to Fluent::Log.per_process_path() is missing:

rotate = @log_rotate_age || @log_rotate_size
actual_log_path = @log_path
# We need to prepare a unique path for each worker since Windows locks files.
if Fluent.windows? && rotate
actual_log_path = Fluent::Log.per_process_path(@log_path, process_type, worker_id)
end
if actual_log_path && actual_log_path != "-"
FileUtils.mkdir_p(File.dirname(actual_log_path)) unless File.exist?(actual_log_path)

To Reproduce

Launch Fluentd with the config below, which enables rotation.

$ bundle exec fluentd -c fluent.conf
#=> The error below occurs.

If you specify the log path, this issue doesn't occur.

$ bundle exec fluentd -c fluent.conf -o fluent.log
#=> Fluentd starts correctly.

If the config doesn't have rotation options, this issue doesn't occur either.

Expected behavior

If rotation is enabled but the log file path is not specified,
the rotation setting is ignored, and Fluentd normally starts with output to standard output as before v1.16.0.

Your Environment

- Fluentd version: 1.16.1
- Operating system: Windows Home 10
- Kernel version: 3.1.7-340.x86_64

Your Configuration

<system>
  <log>
    rotate_age 5
  </log>
</system>

<source>
  @type sample
  tag test
</source>

<match test.**>
  @type stdout
</match>

Your Error Log

C:/Users/reang/Documents/work/fluentd/fluentd/lib/fluent/log.rb:77:in `initialize': no implicit conversion of nil into String (TypeError)

      path = Pathname(path)
                      ^^^^
        from C:/Users/reang/Documents/work/fluentd/fluentd/lib/fluent/log.rb:77:in `Pathname'
        from C:/Users/reang/Documents/work/fluentd/fluentd/lib/fluent/log.rb:77:in `per_process_path'
        from C:/Users/reang/Documents/work/fluentd/fluentd/lib/fluent/supervisor.rb:701:in `setup_global_logger'
        from C:/Users/reang/Documents/work/fluentd/fluentd/lib/fluent/supervisor.rb:624:in `configure'
        from C:/Users/reang/Documents/work/fluentd/fluentd/lib/fluent/command/fluentd.rb:351:in `<top (required)>'
        from <internal:C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:C:/Ruby32-x64/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from C:/Users/reang/Documents/work/fluentd/fluentd/bin/fluentd:15:in `<top (required)>'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/bin/fluentd:25:in `load'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/bin/fluentd:25:in `<main>'

Additional context

No response

@daipom daipom added waiting-for-triage bug Something isn't working and removed waiting-for-triage labels May 29, 2023
@daipom daipom self-assigned this May 29, 2023
@daipom
Copy link
Contributor Author

daipom commented May 29, 2023

There was a nil check for per_process_path on v1.15.3:

if @path && @path != "-"
unless File.exist?(@path)
FileUtils.mkdir_p(File.dirname(@path))
end
if @log_rotate_age || @log_rotate_size
# We need to prepare a unique path for each worker since
# Windows locks files.
if Fluent.windows?
path = LoggerInitializer.per_process_path(@path, process_type, worker_id)
else
path = @path
end
@logdev = Fluent::LogDeviceIO.new(path, shift_age: @log_rotate_age, shift_size: @log_rotate_size)
else
@logdev = File.open(@path, "a")
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant