Skip to content

Commit

Permalink
Merge pull request #2663 from fluent/logrotate-windows
Browse files Browse the repository at this point in the history
Support logrotate on Windows correctly. Fix #2446
Signed-off-by: Masahiro Nakagawa <[email protected]>
  • Loading branch information
repeatedly committed Oct 25, 2019
1 parent 537736f commit 55d6335
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/fluent/command/fluentd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,16 @@

require 'fluent/supervisor'
if opts[:supervise]
if Fluent.windows?
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 @@ -353,13 +353,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,
shift_age: @log_rotate_age, shift_size: @log_rotate_size)
else
File.open(@path, "a")
end
Expand Down

0 comments on commit 55d6335

Please sign in to comment.