diff --git a/lib/fluent/system_config.rb b/lib/fluent/system_config.rb index 2b82835f94..30e1cafdf1 100644 --- a/lib/fluent/system_config.rb +++ b/lib/fluent/system_config.rb @@ -98,6 +98,13 @@ def attach(supervisor) next # doesn't exist in command line options when :emit_error_log_interval system.emit_error_log_interval = @suppress_interval if @suppress_interval + when :log_level + ll_value = instance_variable_get("@log_level") + # info level can't be specified via command line option. + # log_level is info here, it is default value and 's log_level should be applied if exists. + if ll_value != Fluent::Log::LEVEL_INFO + system.log_level = ll_value + end else next unless instance_variable_defined?("@#{param}") supervisor_value = instance_variable_get("@#{param}") diff --git a/test/config/test_system_config.rb b/test/config/test_system_config.rb index ba7feb6317..3fa31db320 100644 --- a/test/config/test_system_config.rb +++ b/test/config/test_system_config.rb @@ -13,11 +13,13 @@ def initalize end class FakeSupervisor + attr_writer :log_level + def initialize @workers = nil @root_dir = nil @log = FakeLoggerInitializer.new - @log_level = nil + @log_level = Fluent::Log::LEVEL_INFO @suppress_interval = nil @suppress_config_dump = nil @suppress_repeated_stacktrace = nil @@ -55,7 +57,7 @@ def parse_text(text) assert_nil(sc.without_source) assert_equal(1, s.instance_variable_get(:@workers)) assert_nil(s.instance_variable_get(:@root_dir)) - assert_nil(s.instance_variable_get(:@log_level)) + assert_equal(Fluent::Log::LEVEL_INFO, s.instance_variable_get(:@log_level)) assert_nil(s.instance_variable_get(:@suppress_repeated_stacktrace)) assert_nil(s.instance_variable_get(:@emit_error_log_interval)) assert_nil(s.instance_variable_get(:@suppress_config_dump)) @@ -99,7 +101,7 @@ def parse_text(text) sc.apply(s) assert_equal(1, s.instance_variable_get(:@workers)) assert_nil(s.instance_variable_get(:@root_dir)) - assert_nil(s.instance_variable_get(:@log_level)) + assert_equal(Fluent::Log::LEVEL_INFO, s.instance_variable_get(:@log_level)) assert_nil(s.instance_variable_get(:@suppress_repeated_stacktrace)) assert_nil(s.instance_variable_get(:@emit_error_log_interval)) assert_nil(s.instance_variable_get(:@suppress_config_dump)) @@ -109,16 +111,43 @@ def parse_text(text) assert_nil(s.instance_variable_get(:@dir_permission)) end - test 'log_level' do + data('trace' => Fluent::Log::LEVEL_TRACE, + 'debug' => Fluent::Log::LEVEL_DEBUG, + 'info' => Fluent::Log::LEVEL_INFO, + 'warn' => Fluent::Log::LEVEL_WARN, + 'error' => Fluent::Log::LEVEL_ERROR, + 'fatal' => Fluent::Log::LEVEL_FATAL) + test 'log_level is applied when log_level related command line option is not passed' do |level| + conf = parse_text(<<-EOS) + + log_level #{Fluent::Log::LEVEL_TEXT[level]} + + EOS + s = FakeSupervisor.new + sc = Fluent::SystemConfig.new(conf) + sc.attach(s) + sc.apply(s) + assert_equal(level, s.instance_variable_get("@log").level) + end + + # info is removed because info level can't be specified via command line + data('trace' => Fluent::Log::LEVEL_TRACE, + 'debug' => Fluent::Log::LEVEL_DEBUG, + 'warn' => Fluent::Log::LEVEL_WARN, + 'error' => Fluent::Log::LEVEL_ERROR, + 'fatal' => Fluent::Log::LEVEL_FATAL) + test 'log_level is ignored when log_level related command line option is passed' do |level| conf = parse_text(<<-EOS) - log_level warn + log_level info EOS s = FakeSupervisor.new + s.log_level = level sc = Fluent::SystemConfig.new(conf) + sc.attach(s) sc.apply(s) - assert_equal(Fluent::Log::LEVEL_WARN, s.instance_variable_get("@log").level) + assert_equal(level, s.instance_variable_get("@log").level) end test 'process global overridable variables' do @@ -130,6 +159,7 @@ def parse_text(text) EOS s = FakeSupervisor.new sc = Fluent::SystemConfig.new(conf) + sc.attach(s) sc.apply(s) assert_equal(0655, s.instance_variable_get(:@file_permission)) assert_equal(0765, s.instance_variable_get(:@dir_permission))