Skip to content

Commit

Permalink
Enable system.log.rotate_... system configuration
Browse files Browse the repository at this point in the history
In the previous versions, log rotation options were supported as
--log-rotate-age or --log-rotate-size via command line options.

On Windows, as fluentd is launched as a windows service, it is
required to configure again via --reg-winsvc-fluentdopt or edit
fluentdopt registry key for customization.

This approach is not convenient for Windows users, so it may be better
to support more comprehensive solution - customize via configuration
file.

This commit introduces such a configurable parameter in .conf

  <system>
   <log>
     rotate_age 5
     rotate_size 1048576
   </log>
  </system>

Signed-off-by: Kentaro Hayashi <[email protected]>
  • Loading branch information
kenhys committed Apr 26, 2021
1 parent b6e76c0 commit 5dfe311
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,26 @@ def initialize(opt)
@chgroup = opt[:chgroup]
@chuser = opt[:chuser]

@log_rotate_age = opt[:log_rotate_age]
@log_rotate_size = opt[:log_rotate_size]
@signame = opt[:signame]

@cl_opt = opt
# parse configuration immediately to initialize logger correctly
@conf = Fluent::Config.build(config_path: @config_path, encoding: @conf_encoding, use_v1_config: @use_v1_config)
@system_config = build_system_config(@conf)
if @system_config.log
@log_rotate_age ||= opt[:log_rotate_age]
if @system_config.log.rotate_age
if %w(daily meekly monthly).include?(@system_config.log.rotate_age)
@log_rotate_age = @system_config.log.rotate_age
else
@log_rotate_age = @system_config.log.rotate_age.to_i
end
end
@log_rotate_size = opt[:log_rotate_size] || @system_config.log.rotate_size
else
@log_rotate_age = opt[:log_rotate_age]
@log_rotate_size = opt[:log_rotate_size]
end
@conf = nil

log_opts = {suppress_repeated_stacktrace: opt[:suppress_repeated_stacktrace], ignore_repeated_log_interval: opt[:ignore_repeated_log_interval],
Expand Down
2 changes: 2 additions & 0 deletions lib/fluent/system_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class SystemConfig
config_section :log, required: false, init: true, multi: false do
config_param :format, :enum, list: [:text, :json], default: :text
config_param :time_format, :string, default: '%Y-%m-%d %H:%M:%S %z'
config_param :rotate_age, :string, default: nil
config_param :rotate_size, :integer, default: nil
end

config_section :counter_server, multi: false do
Expand Down

0 comments on commit 5dfe311

Please sign in to comment.