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

Conversation

cosmo0920
Copy link
Contributor

Signed-off-by: Hiroshi Hatake [email protected]

Which issue(s) this PR fixes:
Fixes #2446

What this PR does / why we need it:

In Windows multi-process environment, we cannot rename a file which is opened by another process.

Then, we should do this:

  • Separate log file for each process on Windows

Docs Changes:

I'll add a note in https://docs.fluentd.org/deployment/logging#log-rotation-setting.

Release Note:

Same as title.

In Windows multi-process environment, we cannot rename a file which is opened by another process.

Then, we should do this:

* Separate log file for each process on Windows

Signed-off-by: Hiroshi Hatake <[email protected]>
@cosmo0920 cosmo0920 assigned repeatedly and cosmo0920 and unassigned repeatedly Oct 23, 2019
@cosmo0920 cosmo0920 requested a review from repeatedly October 23, 2019 02:00
@repeatedly
Copy link
Member

This patch doesn't change file name when no rotate option, right?

@cosmo0920
Copy link
Contributor Author

Right.

lib/fluent/command/fluentd.rb Outdated Show resolved Hide resolved
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.

Signed-off-by: Hiroshi Hatake <[email protected]>
@repeatedly repeatedly merged commit 8535c9a into master Oct 24, 2019
@repeatedly
Copy link
Member

Thanks for the patch!

@ganmacs ganmacs deleted the logrotate-windows branch October 24, 2019 05:10
repeatedly added a commit that referenced this pull request Oct 25, 2019
Support logrotate on Windows correctly. Fix #2446
Signed-off-by: Masahiro Nakagawa <[email protected]>
daipom added a commit to daipom/fluentd that referenced this pull request Feb 13, 2023
When log rotation is enabled on Windows, the log path is separated for
each process.
But, the new path value is not applied to the instance variable, so it
breaks the following behavior, since fluent#2663.

* `File.chown(chuid, chgid, @path)`
* `@logdev.reopen(@path, "a")`.

I can't assume that `File.chown` is used on Windows, but `reopen` must
be fixed.

Signed-off-by: Daijiro Fukuda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot make to rotate log file of fluentd application on windows
3 participants