Skip to content

Commit

Permalink
Windows: Apply the modified log path for rotation to reopen
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
daipom committed Feb 13, 2023
1 parent bf7498d commit 7b285a0
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -563,12 +563,8 @@ def init(process_type, worker_id)
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)
@path = LoggerInitializer.per_process_path(@path, process_type, worker_id) if Fluent.windows?
@logdev = Fluent::LogDeviceIO.new(@path, shift_age: @log_rotate_age, shift_size: @log_rotate_size)
else
@logdev = File.open(@path, "a")
end
Expand All @@ -591,7 +587,7 @@ def init(process_type, worker_id)
$log = Fluent::Log.new(logger, @opts)
$log.enable_color(false) if @path
$log.enable_debug if @level <= Fluent::Log::LEVEL_DEBUG
$log.info "init #{process_type} logger", path: path, rotate_age: @log_rotate_age, rotate_size: @log_rotate_size
$log.info "init #{process_type} logger", path: @path, rotate_age: @log_rotate_age, rotate_size: @log_rotate_size
end

def stdout?
Expand Down

0 comments on commit 7b285a0

Please sign in to comment.