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

Support logrotate on Windows correctly. Fix #2446 #2663

Merged
merged 2 commits into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/fluent/command/fluentd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,17 @@

require 'fluent/supervisor'
if opts[:supervise]
if Fluent.windows?

cosmo0920 marked this conversation as resolved.
Show resolved Hide resolved
if opts[:log_path] && opts[:log_path] != "-"
if opts[:log_rotate_age] || opts[:log_rotate_size]
require 'pathname'

log_path = Pathname(opts[:log_path]).sub_ext("-supervisor#{Pathname(opts[:log_path]).extname}").to_s
opts[:log_path] = log_path
end
end
end
Fluent::Supervisor.new(opts).run_supervisor
else
if opts[:standalone_worker] && opts[:workers] && opts[:workers] > 1
Expand Down
10 changes: 9 additions & 1 deletion lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,21 @@ def initialize(path, level, chuser, chgroup, opts, log_rotate_age: nil, log_rota
@log_rotate_size = log_rotate_size
end

def worker_id_suffixed_path(worker_id, path)
require 'pathname'

Pathname(path).sub_ext("-#{worker_id}#{Pathname(path).extname}").to_s
end

def init(process_type, worker_id)
@opts[:process_type] = process_type
@opts[:worker_id] = worker_id

if @path && @path != "-"
@logdev = if @log_rotate_age || @log_rotate_size
Fluent::LogDeviceIO.new(@path, shift_age: @log_rotate_age, shift_size: @log_rotate_size)
Fluent::LogDeviceIO.new(Fluent.windows? ?
worker_id_suffixed_path(worker_id, @path) : @path,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the process_type is :supervisor, this method call looks unnecessary for me. supervisor's worker id is 0 so the name of log file for supervisor becomes log-supervisor-0.log, right?

Copy link
Contributor Author

@cosmo0920 cosmo0920 Oct 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the process_type is :supervisor, this method call looks unnecessary for me.

Yeah, I think so too before testing for it.
If log-supervisor-0.log and log-0.log are not separated, Fluentd still complains the following error:

log shifting failed. Permission denied @ rb_file_s_rename - ([Some sort of moving files])
log writing failed. closed stream
log shifting failed. closed stream
log writing failed. closed stream
log shifting failed. closed stream
log writing failed. closed stream
log shifting failed. closed stream
log writing failed. closed stream
log shifting failed. closed stream
log writing failed. closed stream
log shifting failed. closed stream
log writing failed. closed stream

I have no idea for this issue....

supervisor's worker id is 0 so the name of log file for supervisor becomes log-supervisor-0.log, right?

Yes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If log-supervisor-0.log and log-0.log are not separated,

I meant it was better the file name of a supervisor was log-supervisor.log not log-0.log.
If you have the intention to do it (adding -supervisor and -0 to a supervisor file name), I'm ok with it since it's a pretty minor point :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have the intention to do it (adding -supervisor and -0 to a supervisor file name), I'm ok with it since it's a pretty minor point :)

Ahhh, OK. Their file names are intended.

shift_age: @log_rotate_age, shift_size: @log_rotate_size)
else
File.open(@path, "a")
end
Expand Down