Skip to content

Commit 484b887

Browse files
committed
Enable system.log.rotate_... system configuration
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]>
1 parent b6e76c0 commit 484b887

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/fluent/supervisor.rb

+19-2
Original file line numberDiff line numberDiff line change
@@ -600,11 +600,28 @@ def initialize(opt)
600600
@chgroup = opt[:chgroup]
601601
@chuser = opt[:chuser]
602602

603-
@log_rotate_age = opt[:log_rotate_age]
604-
@log_rotate_size = opt[:log_rotate_size]
605603
@signame = opt[:signame]
606604

607605
@cl_opt = opt
606+
if File.exist?(@config_path)
607+
# parse configuration immediately to initialize logger correctly
608+
@conf = Fluent::Config.build(config_path: @config_path, encoding: @conf_encoding, use_v1_config: @use_v1_config)
609+
@system_config = build_system_config(@conf)
610+
if @system_config.log
611+
@log_rotate_age ||= opt[:log_rotate_age]
612+
if @system_config.log.rotate_age
613+
if %w(daily meekly monthly).include?(@system_config.log.rotate_age)
614+
@log_rotate_age = @system_config.log.rotate_age
615+
else
616+
@log_rotate_age = @system_config.log.rotate_age.to_i
617+
end
618+
end
619+
@log_rotate_size = opt[:log_rotate_size] || @system_config.log.rotate_size
620+
end
621+
else
622+
@log_rotate_age = opt[:log_rotate_age]
623+
@log_rotate_size = opt[:log_rotate_size]
624+
end
608625
@conf = nil
609626

610627
log_opts = {suppress_repeated_stacktrace: opt[:suppress_repeated_stacktrace], ignore_repeated_log_interval: opt[:ignore_repeated_log_interval],

lib/fluent/system_config.rb

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class SystemConfig
5555
config_section :log, required: false, init: true, multi: false do
5656
config_param :format, :enum, list: [:text, :json], default: :text
5757
config_param :time_format, :string, default: '%Y-%m-%d %H:%M:%S %z'
58+
config_param :rotate_age, :string, default: nil
59+
config_param :rotate_size, :integer, default: nil
5860
end
5961

6062
config_section :counter_server, multi: false do

0 commit comments

Comments
 (0)