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
  • Loading branch information
repeatedly authored Oct 24, 2019
2 parents 1e08d76 + fa0348d commit 8535c9a
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 8535c9a

Please sign in to comment.